Docker Essentials

Docker Logo

Docker Essentials. For the purpose of the examples below the docker container id is 47996381b385

Docker Logo

Containers

Enter Shell

docker container exec -it 47996381b385 /bin/bash

Exit

Exit Container Without Terminating Container

ctrl + p + q

Inspect

sudo docker container inspect 47

the 47 above refers to the docker id

Remove

sudo docker rm 47

Logs

Options:
--details Show extra details provided to logs
-f, --follow Follow log output
--since string Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)
--tail string Number of lines to show from the end of the logs (default "all")
-t, --timestamps Show timestamps
--until string Show logs before a timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)
sudo docker logs 47 --follow

Networking

Show Port Mapping

sudo docker port 47
80/tcp -> 0.0.0.0:8080

Images

List Images

sudo docker images

Search Images from Registry (Docker Hub)

sudo docker search gitlab

Pull Images

sudo docker pull nextcloud
sudo docker pull nextcloud:latest
REPOSITORY TAG IMAGE ID CREATED SIZE
nextcloud latest 30510f8fb18b 2 weeks ago 726MB

Save Container to Image

docker commit f0ff name/name:0.0.1

Volumes

Volumes are used to persist data

Host Volume

Host volumes are mapped to a folder on the host filesystem

-v /home/user/docker/var/www/html /var/www/html

Anonymous Volume

  • /var/lib/docker/volumes/random-hash/_data
  • or
  • /var/lib/docker/volumes/tag/_data
-v /var/www/html

Named Volume

-v name:/var/www/html
volumes:
  - html-data:/var/www/html
  • https://hub.docker.com/
,