Back up, what is a Linux Container?
-
Virtualization method for running multiple isolated Linux systems on top of an existing OS kernel
-
Host system might have Ubuntu/OSX/Windows/CoreOS
-
Subsystem inside might be RHEL, Fedora, etc.
What is Docker?
-
Tool that can package an application and its dependencies in a virtual container that can run on any Linux server.
-
A way to model your containers and more easily manage them.
Why not containers
Note that these are primarily historical reasons
-
Less secure (though a given container is going to have a lot less to attack)
-
Complex (networking, clustering, etc)
Why containers
-
Lightweight
-
Fast to set up
-
Easy to update/change
Components of Docker (and why Docker)
-
Docker client and server (AKA Docker Engine)
-
Docker Images
-
Registries
-
Docker Containers
Docker Engine
-
Docker client(s) talk to the docker server (or daemon) to manage Docker images, containers, volumes, and swarms (clusters).
-
Docker CLI, docker compose, docker swarm are all examples of clients.
Docker images
Containers are launched from images which are in a 'layered' format (every command you run inside a container (or write to a file) is a new layer).
These are portable, and easy to share/store/update.
Registries
Docker stores the images in registries. Docker Hub is what we'll be using (you can create your own but we'll get there eventually).
Containers
The main thing we associate with Docker. Via docker engine, you launch an images from a registry.
So what about "traditional" configuration management tools (like Ansible, Chef, etc)
The general consensus seems to be you should not use any of these tools to manage the container image. A given line of ansible, etc would be seen
as its own layer and this may not work well.
With that said, perhaps there is room for using these tools to manage your deployed containers? Unsure on this...
CLI Commands
-
Type
docker
to see full list of commands.
docker info
Gives stats on many things including:
-
number of containers (running paused, stopped)
-
number of images
docker run
-
Will start running a container.
-
ex.
docker run --name webapps_container -i -t ubuntu /bin/bash
-
-
-i is interactive flag. Means the container will be kept open for you to run commands.
-
-t is tty (or terminal) flag. Means container will provide interactive shell.
-
--name is to give your container a custom name (docker will generate name otherwise).
docker run
cont'd
-
Container is full fledged ubuntu host. Can ask for hostname, ip address, install apt packages etc.
docker ps -a
-
Let you see a listing of running (and stopped) containers.
-
container_id|image|command|created|status|ports|names