How can I install docker on a VM using devcontainer.json? - docker

I want to automate the installation of docker and docker-compose on a newly created VM. Ideally this should be done from the devcontainer.json file such that if a developer opens the project the Debian/Ubuntu packages docker.io and docker-compose are installed automatically.
I tried adding
"initializeCommand": "sudo apt update && sudo apt upgrade -y && sudo apt install -y docker.io docker-compose",
to the main hirarchy of devcontainer.json but it will not run before VS Code starts creating the container. VS Code gives an error message that Docker is not installed, although the initializeCommand command is supposed to be run before the container setup.
Is there any other way of achieving this except using additional tools or e.g. Azure VM templates?

Related

How to install tmux inside a dev container established through the "dev environment" option on docker for a local repository?

I've cloned a github repo and ran into roadblocks trying to set it up locally so used Docker's dev environment option on it. The repo needs tmux as part of the build process and I can't install it inside the Docker environment cause it's linked to the repo and there's no mention of it there
Tried brew install and then realised I'm inside a container...
You can just install it. I started docker a few hours back so I was confused.
Since its a Linux based image just run sudo apt-get update, then apt-get -y install curl and sudo apt-get install tmux in the docker cli

Installing SSH on a Docker image

I'm trying to install SSH on a docker image using the command:
RUN APT INSTALL -Y SSH
This seemingly installs SSH on the image, however if I tunnel into a running container and run the command manually I get prompted to set both Region and Timezone. Is it possible to pass these options to the install SSH command?
The container I am able to manually install SSH on can be started with the command below:
docker container run -it --rm -p 22:22 ubuntu:latest
My Docker Image is as follows:
FROM ubuntu:latest
RUN apt update
apt -y install ssh
Thanks
You can use DEBIAN_FRONTEND to disable interaction with user (DEBIAN_FRONTEND):
noninteractive
This is the anti-frontend. It never interacts with you at all,
and makes the default answers be used for all questions. It
might mail error messages to root, but that's it; otherwise it
is completely silent and unobtrusive, a perfect frontend for
automatic installs. If you are using this front-end, and require
non-default answers to questions, you will need to preseed the
debconf database; see the section below on Unattended Package
Installation for more details.
Like this:
FROM ubuntu:latest
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/London
RUN apt update && \
apt -y install ...

nvidia-docker with nvidia-cuda-toolkit not working between different hosts

I have two machines with different OS. One is ubuntu 18.04 and the other is debian buster. Both of them have docker installations ( from here ) and and the latest nvidia-docker installed. Both systems have a gpu which I want to use inside the containers. So I created a dockerfile which will install everything I require.
FROM ubuntu:18.04
RUN apt update -y
RUN apt upgrade -y
RUN apt install \
nvidia-cuda-toolkit \
-y
In the first machine which has as host ubuntu and a gpu that require .435 driver to work it works fine (docker run --rm --gpus all my-image:1 nvidia-smi)
But when I try the same dockerfile with 0 changes on my Debian machine it will return missmatched version of drivers.
The second matching which has as a host debian and a gpu that require .418 dirver to work it complains about missmatched versions.
Isn't supposed to be host independent installation ? What am I missing and I cannot build the same Dockerfile in both systems?
I can see toolkit bringing drivers on its own but as it is apt installation I have no control over it.
Thank you in advance

How to run Dockerfile or Dock Image to install the python dependencies

Sorry for basic Question, as I am new on Docker and I want to install the dependencies by using the docker file, So please guide me how to run this file on Ubuntu?
Author have written the dependencies in the Dockerfile for building the Opensfm.
GitHub Repository Link
FROM ubuntu:18.04
# Install apt-getable dependencies
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y \
build-essential \
Can anyone guide me how to run the file and install the dependencies on Ubuntu?
You really should follow mchawre's advice and read the docker get-started. However, I can try to direct you into the right direction.
I want to install the dependencies by using the docker file
You have to understand that a docker file compiles to a docker image which then can be run as a docker container. You can think of a docker container as a lightweight virtual machine. With this in mind, your statement does not make sense, since you can not install dependencies for your host system (the system in which you might want to start the docker container) with the help of a docker image. This is not how docker containers are supposed to work.
Instead, the docker file allows you to create a virtualized (isolated) environment in which you can ssh (the docker way: docker exec -it <container_name> bash) and then build the respective application.
If you do not want to mess with docker at all and your systems runs something close to ubuntu:18.04, you can also manually execute the instruction from the docker file on your normal system in order to build your desired application on your system.

Docker-engine confilcts with docker.io

OS: Ubuntu 16.04
Docker version: 1.11.2
I have already installed docker 1.11.2 on my Ubuntu and I want to upgrade it to 1.12. All the steps are as follows:
I download the deb pkg named docker-engine_1.12.3-0~xenial_amd64.
Execute command: dpkg -i docker-engine_1.12.3-0~xenial_amd64 but notes with errors:
docker-engine conficts with docker.io.docker.io (version 1.11.2-0ubuntu5~16.04) has already been installed .
So I have to remove docker first by using commands as below:
service docker stop
apt-get remove docker
apt-get remove --auto-remove docker
rm -rf /var/lib/docker
Go to step 2, but with the same errors.
So, I hope someone would help me solve this problem.
The conflicting packages (which fight over the same binary) are docker.io (from the distribution) and docker-engine (from Docker itself).
Your command above does apt-get remove ... docker. Which achieve nothing for the aforementioned problem.
I have different machines running 16.04 and some use docker.io (easier, no extra repo) whereas others use docker-engine. I am indifferent. Pick on, docker should work just fine.
Firstly restart the ubuntu server with linux command(sudo shutdown -r now), and run the command : apt-get -f install(this command is suggested by the error information), then I install the docker-engine by the following site(https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04).

Resources