Home > Article > Operation and Maintenance > What are the docker operations?
Docker is an open source virtualization technology that allows developers to package applications into a standardized container and then run it on different platforms and deployment environments, making application deployment and migration easier and easier. reliable. This article will introduce some common technologies and operating instructions in Docker operations.
Installing Docker
There are many ways to install Docker. You can use the official installation package or install it directly through the package manager. The following is how to install Docker through the package manager under Ubuntu system.
Start and stop Docker
After the installation is complete, You can start the Docker service through the following command: sudo systemctl start docker
You can check the status of Docker through the following command: systemctl status docker
You can stop the Docker service through the following command: sudo systemctl stop docker
Creation and running of containers
Docker runs applications by running containers. In Docker, a container contains all dependencies and configuration for an application's runtime, as well as the application itself. The following are the steps to create a container:
Where [options] is optional, [image] is the name of the container image, and [command] is the command to be run after the container is started.
For example, you can create a container based on the Ubuntu system through the following instructions and execute the /bin/bash command:
docker run -it ubuntu /bin/bash
In After performing some operations inside the container, you can exit the container by entering exit.
Viewing and deleting containers
Use the following command to view all currently running containers: docker ps
If you need to view all containers, including stopped containers, you can use the following command :docker ps -a
Use the following command to delete a container: docker rm [container]
Container execution and access
Use the following command to execute commands on the container: docker exec [container] [command]
For example, if you need to execute the ls command in a running container, you can use the following command: docker exec -it [container] ls
Run in the container The application can be accessed by IP address or port of access to the host machine. You can use the following command to map the port inside the container to the host's port: docker run -p [host_port]:[container_port] [image]
For example, you can use the following command to map the host's 5000 port to Port 80 inside the container: docker run -p 5000:80 [image]
Building and publishing of images
In Docker, the image is the basis of the container, and one image can be used to create multiple containers. Use Dockerfile to define the build process of an image. The following are the general steps for building an image using Dockerfile:
Where [repository:tag] is the name and version number of the image.
For example, you can use the following Dockerfile to build a Python application image based on Alpine Linux:
FROM python:alpine3.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
Use the following instructions to build this image:
docker build -t mypythonapp .
Use the following command to publish the built image to Docker Hub: docker push [repository:tag]
For example, you can use the following command to push the previously built mypythonapp image to On Docker Hub:
docker push myusername/mypythonapp:latest
Summary
This article introduces some common technologies and operating instructions in Docker operations, including the installation, starting and stopping of Docker, The creation, viewing and deletion of containers, the execution and access of containers, and the construction and release of images. Learning and mastering these technologies and instructions can enable us to better use Docker for application development and deployment.
The above is the detailed content of What are the docker operations?. For more information, please follow other related articles on the PHP Chinese website!