Docker introduction
Docker is an open source application container engine, which is based on the Go language and complies with the Apache2.0 protocol.
Docker allows developers to package their applications and dependencies into a lightweight, portable container that can then be distributed to any popular Linux machine, as well as virtualization.
Containers are completely sandboxed, have no interfaces with each other (like iPhone apps), and most importantly, have very low performance overhead.
Docker advantage
Docker is an open platform for developing, delivering and running applications. Docker enables you to separate your applications from your infrastructure, allowing you to deliver software quickly. With Docker, you can manage your infrastructure the same way you manage your applications. By leveraging Docker’s approach to quickly deliver, test, and deploy code, you can greatly reduce the latency between writing code and running it in a production environment.
Deliver your applications quickly and consistently
Docker simplifies the development lifecycle by allowing developers to work in a standardized environment using native containers of your applications or services.
Containers are well suited for continuous integration and continuous delivery (CI/CD) workflows, consider the following example scenario:
- Your developers write code locally and use Docker containers to share their work with colleagues.
- They use Docker to push their applications into a test environment and perform automated or manual testing.
- When developers find bugs, they can fix them in the development environment and then redeploy them to the test environment for testing and verification.
- When the test is complete, the patch is pushed to production as easily as an updated image.
Responsive deployment and scaling
Docker is a container-based platform that allows for highly portable workloads. Docker containers can run on a developer’s machine, on a physical or virtual machine in a data center, on a cloud service, or in a hybrid environment.
Docker’s portability and lightweight nature also allows you to easily complete dynamically managed workloads and extend or dismantle applications and services in real time as indicated by business requirements.
3. Run more workloads on the same hardware
Docker is light and fast. It provides a viable, economical, and efficient alternative to hypervisor-based virtual machines, so you can leverage more computing power to achieve business goals. Docker is ideal for high-density environments and small to medium sized deployments, where you can do more with less.
A link to the
Docker website: www.docker.com
Github Docker source: github.com/docker/dock…
Docker Hub: hub.docker.com
The installation
Win10 installation
Win10 install package download address is as follows, direct download EXE file installation can, Win10 install after the end, need to restart the computer
www.docker.com/products/do…
After the computer restarts, Docker will automatically start, if WSL 2 installation is incomplete. Bounced prompt
The Docker failed to start icon is displayed on the taskbar
The preceding problem is caused by the lack of the Linux kernel update package. Download the Linux kernel update package and install it
After the installation, you can restart the Docker. After the successful operation of Docker, the client page effect is as follows
The Git Bash command is executed as follows
Ubuntu20 installation
Docs.docker.com/engine/inst…
Uninstall the previous version
sudo apt-get remove docker docker-engine docker.io containerd runc
Copy the code
Install the Docker CE version
To update the apt
sudo apt-get update
Copy the code
Setup package to allow APT to use HTTPS library
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
Copy the code
Add Docker official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Copy the code
Add a stable warehouse address
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Copy the code
To update the apt
sudo apt-get update
Copy the code
Install the Docker
sudo apt-get install docker-ce docker-ce-cli containerd.io
Copy the code
Enter the docker -v command to get the docker version installed successfully
$docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES $DOCker -v Docker version 20.10.5, Build 55C4C88Copy the code
Pay attention to
Docker default installation use name need to use root permission, otherwise there will be permission problems
$ docker ps -a Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.38/containers/json? all=1: dial unix /var/run/docker.sock: connect: permission deniedCopy the code
Add a Docker group to the current user group and you can operate Docker without root permission
sudo usermod -aG docker your-user
After executing the last command, it may not take effect immediately. Re-open a terminal and use docker PS to check the effect. If permission Denied is displayed, restart the computer system
Docker use
Obtaining Node Image
docker pull node
Copy the code
Query downloaded images
docker images
Copy the code
Run the image in interactive mode. Use -v to map the current directory to the workspace directory in the container, and use -p to map the corresponding project port (for example, 8080 is the default for the front-end project).
docker run -ti --name node-env -v $(pwd):/workspace -p 8080:8080 node bash
Copy the code
Query the Node environment after entering the image container
Root @ fce31cf1b9e0: / workspace# v15.12.0 node - vCopy the code
Query the list of running containers
docker ps
Copy the code
Query all containers, including stopped containers
docker ps -a
Copy the code
Start one or more stopped containers
docker start CONTAINER
Copy the code
Stop one or more running containers
docker stop CONTAINER
Copy the code
Interactive access to a running container
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Copy the code
Exit the interface, but do not stop
exit
Copy the code
Remove one or more containers
docker rm
Copy the code
Remove the mirror
docker rmi Image
Copy the code
Export the container’s file system to a tar file (for others to use, unified development environment)
docker export [OPTIONS] CONTAINER
eg.
docker export node-env > node-env-1.tar
docker export --output="node-env-1.tar" node-env
Copy the code
Import the tar file to create an image
docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
eg.
docker import node-env-1.tar node-1
Copy the code
Push the Docker image to the remote registry repository
Docker push eg. Docker push 172.10.10.10:5555 / node: v1.0Copy the code
Build an image based on Dockerfile
docker build - < Dockerfile
Copy the code
View the Help documentation
docker --help
Copy the code