1. Introduce
2. Docker:
-
Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code, you can significantly reduce the delay between writing code and running it in production.
-
Install docs.docker.com
-
Docker Architectures: What is an image/Dockerfile?
- Without going too deep yet, think of a container image as a single package that contains everything needed to run a process. In this case, it will contain a Node environment, the backend code, and the compiled React code.
- Any machine that runs a container using the image, will then be able to run the application as it was built without needing anything else pre-installed on the machine.
- A Dockerfile is a text-based script that provides the instruction set on how to build the image. For this quick start, the repository already contains the Dockerfile.
3.1. Images:
- An image is a read-only template with instructions for creating a Docker container. 3.2. Containers:
- A container is a runnable instance of an image.
- https://www.docker.com/resources/what-container/
- Containers and virtual machines have similar resource isolation and allocation benefits, but function differently because containers virtualize the operating system instead of hardware. Containers are more portable and efficient.
3.3. Docker registries
- A Docker registry stores Docker images. Docker Hub is a public registry that anyone can use, and Docker looks for images on Docker Hub by default. You can even run your own private registry.
- When you use the docker pull or docker run commands, Docker pulls the required images from your configured registry. When you use the docker push command, Docker pushes your image to your configured registry.
3.4. Container images If you’re new to container images, think of them as a standardized package that contains everything needed to run an application, including its files, configuration, and dependencies. These packages can then be distributed and shared with others.
3.5. Docker Hub To share your Docker images, you need a place to store them. This is where registries come in. While there are many registries, Docker Hub is the default and go-to registry for images. Docker Hub provides both a place for you to store your own images and to find images from others to either run or use as the bases for your own images.
3.6. Docker Instructions
- Note:
- The build context is the set of files and folders on your host machine that Docker sends to the Docker daemon when you run:
- The dot (.) at the end of this command tells Docker: “Use the current directory as the build context.”, the folder contain
Dockerfile
$ cat Dockerfile
# Define a new image from Ubuntu 2404
FROM ubuntu:24.04
# Install prerequisites
# - the backslash \ is used for line continuation
# - `-y` to automatically confirm installation
RUN \
# updates the package lists for upgrades for packages that need upgrading,
apt-get update && \
# install cmake, gcc, g++
apt-get install -y cmake && \
apt-get install -y gcc g++ && \
# install cppcheck
apt-get install -y cppcheck && \
# install clang tidy
apt-get install -y clang-tidy && \
# install lcov
apt-get install -y lcov
# Set the working directory inside the Docker image
WORKDIR /cpp-lab
# Copy all things from the build context (the directory where we run docker build) into the docker image being built
# Copy source code from host (build context) to image because the WORKDIR already set
# COPY . .
COPY . /cpp-lab
- Getting Started
- Create, build and push your first image: https://docs.docker.com/get-started/introduction/build-and-push-first-image/