Docker - Getting started
docker --version docker info docker run hello-world # run a new conatiner, in this case `hello-world` docker ps docker ps -a # see running (and stopped) containers docker images # see info about images
# 1. Clone git clone https://github.com/docker/getting-started.git # 2. Build cd getting-started docker build -t docker101tutorial . # 3. Run docker run -d -p 80:80 --name docker-tutoial docker101tutorial
What's the difference between Docker and Docker Compose?
The gist is that
docker manages individual containers while
docker-compose manages multiple containers..
docker-compose are separate packages.
Docker is the CLI managing individual containers while Docker Compose is a tool built on top of docker cli that can be used to manage multi-container applications.
With Docker Compose, you can define stacks in swarm mode. And you do lots of shell scripting as well.
Start docker automatically on boot
See if docker is added to start on system boot
systemctl list-units --type service | grep -i docker
If you don't get anything, enable it
sudo systemctl enable docker
Restart docker containers with system restart
You need to specify a restart policy using the
docker run -d --restart unless-stopped foo
There are four policies
nois default. doesn't restart any containers
on-failureonly restart container if the exit code indicates error instead of success.
alwayswill always restart all containers, even if you had manually stopped them
unless-stoppedwill restart all containers, but not the ones you had manually stopped before
With Docker Compose,
restart has been supported since version 2, and in version 3 you also get
restart_policy but it only applies to swarms
version: '2' services: web: image: apache restart: always
- Overview of Docker Compose
- StackOverflow: What is the difference between docker and docker-compose
- Start containers automatically
- Ensuring Containers Are Always Running with Docker's Restart Policy
- StackOverflow: Docker-Compose Restart Policy
- Compose file reference: restart
- Compose file reference: RESTART_POLICY
- Configure Docker to start on boot