Examine the evolution of virtualization technologies from bare metal, virtual machines, and containers and the tradeoffs between them.
Explores the three core Linux features that enable containers to function (cgroups, namespaces, and union filesystems), as well as the architecture of the Docker components.
Install and configure Docker Desktop
Use publicly available container images in your developer workflows and learn how about container data persistence.
Building out a realistic microservice application to containerize.
Write and optimize Dockerfiles and build container images for the components of the example web app.
Use container registries such as Dockerhub to share and distribute container images.
Use Docker and Docker Compose to run the containerized application from Module 5.
Learn best practices for container image and container runtime security.
Explore how to use Docker to interact with containers, container images, volumes, and networks.
Add tooling and configuration to enable improved developer experience when working with containers.
•Developer Experience Wishlist
Deploy containerized applications to production using a variety of approaches.
We saw the basic syntax for running containers earlier in the course:
docker run <CONTAINER_IMAGE_NAME>
This lesson provides a summary of the most important configuration options when running containers with Docker.
There are two primary ways to run containers with Docker Desktop, docker run
and docker compose
.
For one-off containers, you can use docker run
is sufficient.
That being said, docker compose allows you to specify all of your application configuration within a YAML
file, making it more intuitive and easier to work with for applications with multiple containerized services.
-d
(Detach): Run a container in the background.docker run -d ubuntu sleep 5
--entrypoint
(Entry Point): Override the entry point defined in the Dockerfile.docker run --entrypoint echo ubuntu hello
--env
or -e
(Environment Variables): Set environment variables at runtimedocker run --env MY_ENV=hello ubuntu printenv
--init
(Initialization): Run Docker's initialization script and spawn the process as a subprocess.docker run --init ubuntu ps
-i
(Interactive) and -t
(TTY): Have an interactive TTY session inside the container.docker run -it ubuntu
--mount
and --volume
(Volume): Persist data outside of the container layer in a volume.docker run \
-e POSTGRES_PASSWORD=foobarbaz \
--volume pgdata:/var/lib/postgresql/data \
postgres:15.1-alpine
--name
(Name): Provide a specific name for a container.docker run -d --name my_container ubuntu sleep 99
--network
or --net
(Network): Connect to a specific Docker network.docker run --network my_network ubuntu
--platform
(Platform): Specify the architecture to run the container image.docker run --platform linux/arm64/v8 ubuntu dpkg --print-architecture
--publish
or -p
(Publish): Connect a port from the host system to that of the container.docker run -p 3000:3000 api-node
--restart
(Restart): Restart the container based on the specified policy (always, unless-stopped, or never).docker run --restart unless-stopped ubuntu
```
12. `--rm` (Remove): Remove the container when the process exits.
```bash
docker run --name this_one_will_remain ubuntu
docker run --rm --name this_one_will_be_gone ubuntu
# grepping for these containers shows that the --rm one is gone
docker image ls -a | grep this_one_will
--cap-add
and --cap-drop
: Specify which Linux capabilities should be accessible from the container.--cgroup-parent
: Specify which cgroup ID the container should be associated with.--cpu-shares
: Specify the percentage of CPU cycles the container should have access to.--cpuset
: Specify which CPU cores the container should run on.--device-read-bps
and --device-write-bps
: Control the device throughput and bandwidth the container has access to.--gpus
: Access GPUs within the container.--health-*
(e.g. --health-cmd
, --health-interval
, etc...): Specify a health check for Docker to periodically ping the container.--memory
: Specify the amount of memory the container process should have access to.--pids-limit
: Specify the number of subprocesses the container should be allowed to manage.--privileged
: Grant the container access to all privileges.--read-only
: Set the container layer of the file