Docker Basics
by John Vincent
Posted on May 30, 2021
Let's discuss Docker basics
This is part of a series of discussions regarding Deploying TaskMuncher, a React and Node application, to a Multi-Container Docker Environment at AWS using Dockerhub and Travis CI
For more details, please see Overview of Create Multi-Container Docker TaskMuncher Application at AWS
Docker
Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime. Using Docker, you can quickly deploy and scale applications into any environment and know your code will run.
Docker works by providing a standard way to run your code. Docker is an operating system for containers. Similar to how a virtual machine virtualizes (removes the need to directly manage) server hardware, containers virtualize the operating system of a server. Docker is installed on each server and provides simple commands you can use to build, start, or stop containers.
When you are running Docker, every single container you are running is running inside of a Virtual Machine running Linux.
A Docker Image is a single file with all the dependencies and configuration required to run a program.
A Docker container is used to run a single instance of a Docker image.
Each running Docker container has its own file system.
Docker Cheat Sheets
Docker Compose Cheat Sheets
Install Docker on Mac
DockerHub
has a library of containers.
- Get Docker
- Downloads
Docker.dmg
- Install
Docker.app is installed in /Applications
Docker downloads are stored in $HOME/Library/Containers/com.docker.docker/Data
Start Docker Desktop App
Click whale icon in top status bar to execute Docker.app
Login using Docker Id and Password
Visual Studio Docker Hub Extension
- Go to Extensions and search for
@id:ms-azuretools.vscode-docker
, which will findDocker 1.11.0
- Install
Click the whale icon in left menu.
Under Registries:
- click
Connect Registry
- enter Id and Password
Visual Studio yaml Extension
- Go to Extensions and search for
redhat.vscode-yaml
which findsYAML by Red Hat
- Install
settings.json
"[yaml]": {
"editor.autoIndent": "advanced"
}
Basic Docker
docker version
docker info
docker images
lists all images stored locally
docker run <image-name>
creates and runs a container using the specified image
docker ps
lists all the containers currently up
docker ps -a
lists all the containers, also the ones stopped
docker rm <container-name>
stops and removes the specified container
docker pull <image-name>
downloads the specified image from Docker Hub
docker rmi <image-name>
removes the specified image from your machine
docker system prune
remove stopped containers
docker logs <container id>
retrieves Log Outputs or see $HOME/Library/Containers/com.docker.docker/Data/log/
docker stop <container id>
sends a SIGTERM signal to the container
docker kill <container id>
sends a SIGKILL to the primary task in the container, will stop immediately.
docker run -it <container id> sh
starts with a shell
-i
attach to stdin-t
ensure text output is in a nice format- To exit the container,
control d
docker exec -it <container id> <command>
execute command in a running container
Basic Docker Compose
Docker compose makes it a lot easier to configure and run a docker container.
docker-compose -v
docker-compose up
,
docker-compose up -d
docker-compose up --build
docker-compose down
docker-compose ps
Simple example of running a Docker container
docker run -d -p 80:80 docker/getting-started
which creates an image docker/getting-started
in container gracious_einstein
To run the app
http://localhost:80