1. Prologue
1.1 Why I output this document
When ourtest has dependencies with the environment, how to get rid of the issue whichcaused by these dependency issue after you change to another test environment,i.e., we test it on Ubuntu16.04 and our customer use Ubuntu22.04?
I think Docker could work for you in a performance-intensive and low overhead approach. It is a very good & popular tool for us to make the develop/deploy environmentportable, and many people don’t get familiar of it, much less get the hang of it.
1.2 Who will be the reader of this document
Any people who will develop or deploythe software on Linux system that have the specific requirement of theenvironment configuration, you need to learn it to make the environmentconfigurations portable.
2. What's docker
2.1 Introduction
Docker is a tool that allows developers, sys-admins etc. To deploy their applications easily in a sandbox (calleds) to run on the host operating system i.e., Linux. The key benefit of Docker is that it allows users to package an application with all its dependencies into a standardized unit for software development. Unlike virtual machines,s do not have high overhead and hence enable more efficient usage of the underlying system and resources.Find the difference between Virtual Machine VS Docker from the link below:
https://cloudacademy.com/blog/docker-vs-virtual-machines-differences-you-should-know/
https://www.freecodecamp.org/news/a-beginner-friendly-introduction-to-containers-vms-and-docker-79a9e3e119b/
2.2 Docker Image and Container
Docker images are stored as a series of read-only layers:
When a is started, Docker adds a read-write layer on top of the read-only layers/images:
3. Get started to learn the basic operation of Docker
3.1 How to install Docker on Ubuntu16.04
3.1.1 Install relevant package to access apt software package via https:
- sudo apt-get update
- sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
3.1.2 Prepare Docker GPG private-key to verify the integrity of the downloaded Docker package.
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
3.1.3 Add the Docket APT package download link source:
- echo “deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu xenial stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
3.1.4 Update apt source and intall Docker:
- sudo apt-get update
- sudo apt-get install docker-ce
3.1.5 Check Docker version
-
sudo docker version
3.2 How to create & manage docker image
3.2.1 Pull image manually
pull the base image file from docker hub repository with command [docker pull ubuntu] and check if the image pull down successfully via [docker images] to check the current images we have.
3.2.2 Build with dockerfile
- Note: we could find that the difference between
docker pull
&docker build
, docker build creates multiple images, the final one based on original image specified in 'From' parameters, and integrates the tools we want with apt-get install command in 'RUN' parameters.
3.3 How to create & mange
3.3.1 docker create & docker start
we could create docker via docker create
and start&enter via 'docker start' like the picture shows below
3.3.2 docker run
We could also use [docker run] to create&start&enter the like the picture shows below
3.4 Install tool in docker:
3.5 How to commit the modification in to a new image
3.6 How to save image to a file or load image from file
3.7 How to export to a file and import it as an image
We could find that, docker save
command can't save the to file, but docker export
command can do that, the file created by [docker export] command could import to docker via docker import
command and the import result will be convert the to an image file.
3.8 How to remove docker
-
sudo apt-get autoremove docker docker-ce* docker-engine docker.iod runc
-
check if the install package is still there via
dpkg -l | grep docker
, if yes, we could remove the install package viadpkg -l | grep ^rc | awk '{print }' | sudo xargs dpkg -P
4. Appendix
4.1 Docker Command
N.o | Command | Description |
---|---|---|
1 | docker build | Build an image from a Dockerfile. |
2 | docker images | Show the image information on the docker. |
3 | docker ps | Show the information on the docker. |
4 | docker run | Create & start a new with the command you want to run. |
5 | docker start | Start one or more stoppeds, -I will attach STDIN. |
6 | docker stop | Stop one or more runnings. |
7 | docker commit | Create a new image from a's changes. |
8 | docker rmRemove one or mores. | |
9 | docker rmi | Remove one or more images. |
10 | docker export | Export a's filesystem as a tar archive. |
11 | docker import | Import the contents from a tarball to create a filesystem image. |
12 | docker save | Save one or more images to a tar archive (streamed to STDOUT by default). |
13 | docker load | Load an image from a tar archive or STDIN. |
14 | docker pull | Pull an image or a repository from a registry. |
4.2 Reference Link
N.o | TopicReference | Link |
---|---|---|
1 | Official website | https://hub.docker.com/ |
2 | Documentations of Docker | https://docs.docker.com/get-started/overview/ |
3 | Install docker on Ubuntu | ttps://blog.csdn.net/weixin_42178777/article/details/131741720 |