As a lightweight container technology, Docker makes the process of software development, testing and deployment more efficient and convenient. For novices, the concept and commands of Docker may be a bit complicated, so this article will help you quickly understand and get started with the basic operations of Docker through a quick guide.

Basic Concepts of Docker

  • Image: The application template in Docker that includes all the environments and configurations needed to run the application.
  • Container: A running instance of an image; it is where the application actually runs.
  • Dockerfile: A file that describes how to build an image, containing the necessary commands and instructions.

Installing Docker

There are some differences in installing Docker on macOS, Windows, and Linux, but you can download the installation package directly from the Docker official website. After installation, you can check the Docker version and verify the installation by running the following command:

1
docker --version

Quick Overview of Basic Commands

Download a Docker image.

1
docker pull [Image]

View currently running containers

1
docker ps

Stop the specified container

1
docker stop [ContainerID]

Delete a stopped container

1
docker rm [ContainerID]

Delete the specified image

1
docker rmi [ImageName]

The basic structure of a Dockerfile

1
2
3
4
5
6
7
8
9
10
11
# Using a base image
FROM python:latest

# Set the working directory
WORKDIR /app

# Copy the file to the container
COPY . /app

# Startup Command
CMD ["python3", "app.py"]
docker build test
docker build test

Building and running a custom image

Create an image

test-docker
1
docker build -t myapp .

After the image is built, run

test-docker
1
docker run myapp
docker build run
docker build run

If you have any questions, feel free to leave a comment so we can discuss and learn together
If you found this article helpful, please respond with an emoji, leave a comment, or share it with more friends Thank you


Total Site Visits:times
This site was created by LinWhite using the Stellar 1.29.1 theme.
All articles on this site, unless otherwise stated, are licensed under the CC BY-NC-SA 4.0 license. Please credit the source when republishing.