This account is no longer maintained, please go to blog to read the original.
preface
This article assumes that the reader is a developer and familiar with the Linux environment, so it will not cover basic technical concepts. The command line environment is used as an example in Linux.
Contents summary
This article includes the following:
- Install Docker in CentOS7
- Make a Docker image
- Deploy the service through Docker
Further reading
For those who are already familiar with Docker, it is recommended to read Docker + Jenkins to build CI/CD environment. After reading this article, you will have achieved the following results:
| Deploy the application from a Docker container using only a COMMIT (GitHub).
This includes the following operations:
- Check out the code
- Run the test
- Compile the code
- SonarQube (Code Quality Management tool) analysis of code
- Create a Docker image
- Push an image to a Docker Hub
- Pull and run the image
To put it simply, it is about shenbing combined with the background of Ping an CaaS.
The body of the
Start a simple Web application with Docker
Install Docker in CentOS7
Docker is now available in two versions, Docker CE and Docker EE. Both versions are officially maintained. EE is the commercial version, which provides technical support for the certified OS, cloud platform layer, authentication (authentication) systems such as LDAP and Active Directory, and security support for image authentication. This article uses Docker CE (Community Edition) as an example.
-
OS Prerequisites
To install Docker CE, you need a maintenance version of CentOS 7. Archived versions are not tested and supported.
The centos-Extras repository needs to be enabled. This is enabled by default.
The Overlay2 storage driver is recommended.
-
Delete the old version
Older versions of Docker were called Docker or Docker-Engine. If they are installed, remove them first, including the associated dependencies.
(sudo) yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine Copy the code
If Yum reports that these are not installed, that’s OK.
/var/lib/docker contains default contents such as images, containers, volumes, networks, etc. The Docker CE installation package is now called docker-CE.
-
Install the Docker CE
There are 3 ways to install Docker CE:
- Most people use repositories through package management tools. This approach is officially recommended because of the simplicity of the steps and the ease of managing the version.
- Some people download RPM packages and install them manually, and manage the versions completely manually. This can be useful in an environment that is disconnected from the Internet.
- In test and development environments, some people install Docker through automated scripts.
-
Install through the package management tool repository
4.1 Configuring the Software Source Repository
- Dependency packages need to be pre-installed.
yum-utils
provideyum-config-manager
Tools, and thendevice-mapper-persistent-data
andlvm2
bedevicemapper
Storage driver dependencies.(sudo) yum install -y yum-utils \ device-mapper-persistent-data \ lvm2 Copy the code
- Use the following command to configure the stable warehouse source.
(sudo) yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo Copy the code
4.2 Installing a Docker CE
(sudo) yum install docker-ce docker-ce-cli containerd.io
If the command line prompts you to accept the GPG key, confirm that fingerprint is the same as the following. 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35 if the same, accept it.
4.3 (Optional) Install the specified version of Docker CE.
- Sort lists available versions in the repository source for example:
$docker yum list - ce - showduplicates | sort - r docker - ce. X86_64 3:18. 09.1-3. El7 docker - ce - stable docker - ce. X86_64 3:18.09.0-3.el7 docker-ce-stable docker-ce. X86_64 18.06.1. Ce-3. el7 docker-ce-stable docker-ce. X86_64 18.06.0.ce-3.el7 docker-ce-stableCopy the code
- Install the spec version with a valid package full name
The full name of a package consists of two parts. These are (1) package names (docker-ce) plus version strings (column 2) starting with the first colon (:) and ending with the first hyphen (-), followed by a hyphen (-).
For example, docker-CE-18.09.1.
(sudo) yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
After completing the above steps, Docker is installed and a Docker group is created in the system, but no users have been added to the group.
4.4 start the Docker
(sudo) systemctl start docker
4.5 Verifying Docker CE installation by running the Hello-world image.
(sudo) docker run hello-world
- Dependency packages need to be pre-installed.
Make a Docker image
You can refer to Docker Cheat Sheet about the docker command.
-
Search for available Docker images
The easiest way to use Docker is to start with an existing container image. The official Docker website has a dedicated page to store all available images, the url is: index.docker. IO. You can browse this page to find the image you want to use, or use a command-line tool to retrieve it.
-
Docker pull
$Docker images REPOSITORY TAG IMAGE ID CREATED SIZE Hello -world latest FCE289e99eb9 3 months ago 1.84kB Kindest /node V1.12.5eadc0ca522 5 months ago 1.5GB k8s.gcr. IO/kube-proxy-AMd64 v1.11.3be5a6e1ecFA6 7 months ago 97.8MB K8s.gcr. IO /kube-controller-manager-amd64 v1.11.3a710d6a92519 7 months ago k8s.gcr. IO /kube-apiserver-amd64 v1.11.3a710d6a92519 8 months ago k8s.gcr. IO /kube-apiserver-amd64 v1.11.3a710d6a92519 IO /kube-scheduler-amd64 v1.11.3CA1F38854F74 7 months ago 51.8 MB K8s.gcr. IO/coreDNS 1.1.3b3b94275d97c 10 months ago 45.6MB K8s.gcr. IO /etcd-amd64 3.2.18b8df3b177be2 12 months ago 219MB K8s.gcr. IO /pause 3.1 DA86e6ba6CA1 15 months ago 742kB $docker pull busyBox Using default tag: latest latest: Pulling from library/busyboxfc1a6b909f82: Pull complete Digest: sha256:954e1f01e80ce09d0887ff6ea10b13a812cb01932a0781d6b0cc23f743a874fd Status: Downloaded newer image forBusybox: Latest $Docker images REPOSITORY TAG IMAGE ID CREATED SIZE Busybox latest AF2F74C517AA 5 days ago 1.2MB Hello -world latest FCE289E99eb9 3 months ago 1.84kB Kindest /node V1.12.2 58eADc0CA522 5 months ago 1.5GB K8s.gcr. IO /kube-proxy-amd64 v1.11.3be5a6e1ecFA6 7 months ago k8s.gcr. IO /kube-proxy-amd64 v1.11.3be5a6e1ecfa6 7 months ago K8s.gcr. IO /kube-apiserver-amd64 V1.11.3de571b6587b 7 months ago 187MB k8s.gcr. IO /kube-apiserver-amd64 V1.11.3de571b6587b 7 months ago 187MB K8s.gcr. IO /kube-controller-manager-amd64 v1.11.3a710d6a92519 7 months ago 155MB k8s.gcr. IO/coreDNS 1.1.3b3b94275d97c 10 have a line 45.6 MB k8s. GCR. IO/etcd - amd64 3.2.18 b8df3b177be2 have line 219 MB k8s. GCR. 3.1 da86e6ba6ca1 15 IO/pause months ago 742kBCopy the code
-
Make a Docker image
Grammar: docker build [OPTIONS] PATH | | – URL
The docker build command builds an image from a Dockerfile and a “context”. The context of a build is a collection of files at a specific location, which can be specified by PATH or URL. In other words, you can specify a “context” through a Git repository.
3.1 write Dockerfile
I wrote a simple Web application in go. Now I’m making my own Web application image, called “Go-Server-9860”, based on the basic image busyBox.
- Writing a Dockerfile Dockerfile can be seen here.
3.2 Creating a Mirror
Use the docker build command to create the image by specifying the URL.
Example: the docker build – t go – https://github.com/aruruka/hello-world.git#master:docker_basis server – 9860
3.3 Running An Image
Start a container from the background:
Docker run -d --name go-server-9860 -p 127.0.0.1:9860:9860/ TCP --rm go-server
Enter a container and assign a terminal:
docker exec -it go-server-9860 sh
To send SIGKILL to a container:
docker kill go-server-9860
Access the Web service you just deployed
# View the container being cloud from:
docker ps | sed -n '1p; / go - server/Ip # test port is listening on the host Telnet 127.0.0.1 9860 # curl http://127.0.0.1:9860/world access serviceCopy the code