What are the docker operations?

WBOY
Release: 2023-05-13 16:10:08
Original
650 people have browsed it

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.

  1. Update the software package list: sudo apt-get update
  2. Install Docker dependency packages: sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software- properties-common
  3. Download and add Docker's official GPG key: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  4. Add Docker's stable version software source: sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  5. Update software Package list: sudo apt-get update
  6. Install Docker CE (Community Edition): sudo apt-get install docker-ce

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:

  1. Download a standard container image: docker pull [image]
  2. Create a new container: docker run [options] [image] [ command]

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:

  1. Create a project directory and create a file named Dockerfile in the directory.
  2. Define the base image, install the application's dependency packages, copy the application's code files and other construction steps in the Dockerfile.
  3. Use the following instructions to build the image: docker build -t [repository:tag] .

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!