-
-
Notifications
You must be signed in to change notification settings - Fork 1
HOWTO dev docker_setup
-
How To Install and Use Docker on Ubuntu 18.04, by DigitalOcean
-
How to install Docker On Ubuntu 18.04, by PhoenixNap
-
How to install docker-compose On Ubuntu 20.04 by DigitalOcean
docker-ce
is provided by docker.com, docker.io
is provided by Debian.
The first installs all the dependencies (possibly creating library duplicates), the second one typically goes the APT way and uses dynamic linking.
Make sure any old version is uninstalled:
$ sudo apt-get remove docker docker-engine docker.io
Install & enable the service:
$ sudo apt install docker.io
$ sudo systemctl start docker
$ sudo systemctl enable docker
Verify the installation:
$ docker -v
$ sudo service docker status
$ sudo docker info
Prefixing some commands with sudo
may force you to use sudo's -E
parameter to pass over any environment variable you may be using. For instance, something like DB_DATA=/my_data/folder docker run mongo -d
, when using sudo
would need to become sudo -E DB_DATA=/my_data/folder docker run mongo -d
, which is a minor inconvenience but nevertheless required.
If you want to avoid typing sudo
before each command, simply add your user to the docker
group.
To do that, create the group if it's missing:
$ sudo groupadd docker
Add your current user (env variable $USER
) to it:
$ sudo usermod -aG docker $USER
....Then log-out & re-log in to make the changes effective.
It is also possible to run Docker in "rootless" mode, but this currently has limitations. Check out the official Docker guide on rootless mode and security.
-
docker pull image_name:versioning_tag
will download on localhost from the official public Docker registry the Docker image namedimage_name
, associated with the specifiedversioning_tag
; for instance,docker pull mongo:4.2.6
will download the 4.2.6 version of the MongoDB image. -
docker images
gives you a list of the existing Docker images on localhost. -
docker ps
gives you a list of the running containers (ps -a
to list also stopped containers). -
docker build .
creates a local Docker image from theDockerfile
in the current directory. -
docker run --name container_name -d image_name
runs a container in detached mode, (creating it with the specified name), using the Dockerimage_name
factory image; if the-d
flag is not present, the container will run in foreground and you will need to press -c to exit. -
docker stop service_name_or_container_id
stops a container running in the background or in another process. -
docker start container_id
will restart a previously stopped container. -
docker rm container_name_or_id
removes an existing container. -
docker rmi image_name
removes an existing Docker image. -
docker exec container_name_or_id context_command
will executecontext_command
inside the running container, whatever that may be. For exampledocker exec -it mongo bash
will open an interactive bash terminal in a running container named "mongo" (this way, you can connect to the database running inside the container, by executing then themongo
client after the new bash shell opens up).
See the official Docker CLI docs for more information.