★ WELCOME ★

This is an old revision of the document!


Docker Reference Page

Tom Clark 2022/02/12 09:25

If you are new to Docker technology, here is a guide that I found very helpful:

Docker Tutorial for Beginners [FULL COURSE in 3 Hours]
by TechWorld with Nana via Youtube

Base Questions

What does a Docker structure look like?

  • Layers of images
    • Base image is usually a tiny Gnu/Linux footprint;
    • Intermediate images are libraries/services like a database, etc.;
    • The application image is the top layer).
  • Mostly Linux Base Images, like Alpine, because they are so small in size

Why Docker vs a Virtual Machine?

  • Docker is less resource hungry because Docker containers use the host Linux kernel.

Where are docker images stored?

  • I think the big public repository is hub.docker.com.

How to install Docker?

  • This can change, so get the latest information by doing an Internet search “Install Docker” and go to the official docker documentation. Also, you want to check with your distribution as well, because when I went to install Docker using the official docker documentation for Ubuntu I ran into some problems.
  • Keep in mind that there are two base flavors of Mint. Linux Mint (based on Ubuntu) and Linux Mint LMDE (based on Debian). And your Mint is based upon a particular edition of the upstream repositories… So, you want to follow the Docker install instructions for your distribution edition or the upstream edition your Mint is based on. Try [cat /etc/upstream-release/lsb-release] in the terminal or visit https://en.wikipedia.org/wiki/Linux_Mint#Ubuntu-based_editions.

Basic Commands

# Display images that are running:
docker ps
  -a = list both running and stopped images

# Display all docker images downloaded to and stored on your machine:
docker images

# Download a container based on latest version of an image:
docker pull [name-of-image] 

# Initial start of a container based on a specific version of image (pulls image from hub if not already downloaded to your machine:
docker run [flags] [name-of-image or id-of-image][:version] 
  -d = runs in detached mode (so you can continue to use your terminal instance.
  -p[host port]:[container port] = port binding the host's bare metal port and binding it to the application's port (i.e. -p6000:6000)
  --name [user assigned container name] = assign your container a name (i.e. --name mydockercontainer)

# Start a container that has already been run:
docker start [container name or last 12 positions of container id] 

# Stop a container:
docker stop [container name or last 12 positions of container id] 

# To view a container's logs:
docker logs [container name or last 12 positions of container id] 

# To enter into a terminal of a running container
docker exec -it [container name or last 12 positions of container id] /bin/bash

# To list Docker networks:
docker network ls

Docker Networks

In order for containers to talk to each other you have to setup a docker network. Normally, unless you are a developer, you would not have to do this, but if you do then review Nana's video, Developing with Containers chapter below. Or reference a more up-to-date tutorial or documentation. However, you can also setup a Docker network automatically when you use Docker compose. See topic below.

Docker Compose

Placeholders are in square [] brackets and comments are in curly {} braces in the template below. Note that in the template I have laid out 2 different Docker containers in a single compose file. When you do this, a common Docker network is created. Also, indentation must be precise for this to work (supposedly).

version:'3' {This is the version of Docker Compose the script is for.}
services:
  [user assigned name]: {same as docker run --name flag}
    image: [image name][:version] {name of image from Docker hub}
    ports:
      - [host port]:[container application port]
    environment:
      - [environment setting]=[assigned value]
  [user assigned name]: {same as docker run --name flag}
    image: [image name][:version] {name of image from Docker hub}
    ports:
      - [host port]:[container application port]
    environment:
      - [environment setting]=[assigned value] 

The contents of the file above would be saved in a text file saved with a .yaml extension.

To start a Docker compose file, run:

docker-compose [flags] [command]
  -f [name of yaml file] 

Commands:

  up = start a Docker Compose configuration
  down = stop a Docker Compose configuration

Examples:

docker-compose -f mycontainers.yaml up
docker-compose -f mycontainers.yaml down

Docker Volumes

Persistent data between container restarts.

Packaging & Distributing Your Own Docker Containers into Images

Again, check with Nina on how to do this. Clients of Dockerized applications would not normally have to do any of this.

https://youtu.be/3c-iBn73dDE?t=6120 https://youtu.be/3c-iBn73dDE?t=8844

Print/export