Index

Installing Docker under Linux (Ubuntu / Mint)

Download the latest version of docker here (pool/stable):
https://download.docker.com/linux/ubuntu/dists/
If you need to know the Ubuntu release name for a version, you can find it here:
https://wiki.ubuntu.com/Releases
Likewise for Linux Mint:
https://www.linuxmint.com/download_all.php
hello world
sudo docker run hello-world
uninstall docker
sudo apt remove docker docker-engine docker.io containerd runc

using docker

show general info
sudo docker info
show running containers
sudo docker ps
show ALL containers
sudo docker ps -a
sudo docker ps --all
create and start new container
sudo docker run [image]
start an existing container
docker start [id]
open linux shell to container
sudo docker exec -it [container_id] bash
stop container (find container_id using docker ps)
sudo docker stop [container_id]
remove image
docker rm -f [name]
update docker image
sudo docker pull [image]
list volumes
docker volume ls
get info on volume
docker volume inspect [volume_name]
remove volume
docker volume rm [volume_name]
copy from host to container
docker cp [file] [container]:[path]
copy from container to $pwd on host
docker cp [container]:[path] .
copying files between containers is not supported

docker run (new container)

run interactive linux docker
sudo docker run -it ubuntu bash
interactive (pseudo-TTY)
-it
automatically remove container and associated file system on exit
--rm
name a container
-- name [name]
assign an environment variable
-e [name]=[value]
launch in background (detached)
-d
bind image port to host
-p [host_port]:[container_port]
make port available to localhost only
-p 127.0.0.1:[host_port]:[container_port]
mount persistent volume on image
-v [host_dir]:[image_dir]
set work directory
-w [dir]
--workdir [dir]
start container every time docker starts
--restart
documentation
https://docs.docker.com/engine/reference/commandline/run/

docker network

list networks
docker network ls
create a new network
docker network create [network]
delete network (disconnect containers first)
docker network rm [network]
connect container to network
docker network connect [network] [container]
disconnect container from network
docker network disconnect [network] [container]
examine network details
docker inspect [network]
documentation
https://docs.docker.com/engine/reference/commandline/network_create/
https://docs.docker.com/engine/reference/commandline/network_ls/
https://docs.docker.com/engine/reference/commandline/network_connect/
https://docs.docker.com/engine/reference/commandline/network_inspect/

docker images

common images
httpd
microsoft/mssql-server-linux
openjdk
postgres
ubuntu
image hub
https://hub.docker.com/search?q=&type=image

Postgres image

pull latest stable
docker pull postgres
pull specific version
docker pull postgres:[postgres_version]
run image
docker run --name postgres -e POSTGRES_PASSWORD=[password] -e POSTGRES_DB=[database_name] -p 127.0.0.1:5432:5432 -v [persistent_dir]:/var/lib/postgresql/data  postgres
environment variables
POSTGRES_PASSWORD=super user password
POSTGRES_USER=super user name
POSTGRES_DB.POSTGRES_USER=super user name
POSTGRES_DB=default database, defaults to [POSTGRES_USER]
documentation
https://docs.docker.com/samples/library/postgres/

Java image

java hello world
sudo docker run --rm openjdk java -version
mounting and running an application
sudo docker run --rm -v "$PWD":/app -w /app openjdk java -jar [jar]
sudo docker run --rm -v "$PWD":/app openjdk java -jar app/[jar]
documentation
https://github.com/docker-library/openjdk
https://hub.docker.com/_/openjdk/

Apache image

Apache hello world
sudo docker run --rm -p 80:80 httpd
mount document root
sudo docker run --rm -p 80:80 -v [dir]:/usr/local/apache2/htdocs/ httpd:2.4
reload config
docker cp httpd.conf [container]:/usr/local/apache2/conf/httpd.conf
docker exec -it [container] apachectl graceful
documentation
https://hub.docker.com/_/httpd