centos installation operation and partial understanding of docker

Posted by ThaboTheWuff on Fri, 10 May 2019 15:47:38 +0200

After installing the docker locally the other day and getting familiar with the commands, I still couldn't help but go through a wave of golang mirror deployments on centos. Here are my steps and some ideas.
Prepare: A networked centos server with docker installed

1. Not to mention, write a Dockerfile (just want to experience the dockerfile process, so choose the installation method of yum)

# docker build
# Version 1.0
#
FROM centos
#
MAINTAINER yancoder@163.com
#
RUN yum install -y epel-release
RUN yum install -y docker-io
RUN yum provides '*/applydeltarpm'
RUN yum install deltarpm -y
RUN yum install -y gcc
RUN yum install -y go
RUN mkdir -p /data/gopath
ENV GOPATH /data/gopath
ADD src/ /data/gopath/src
ADD pkg/ /data/gopath/pkg
ADD test.go /data/gopath/test.go
WORKDIR /data/gopath
RUN go build -o server.bin test.go
#
CMD /data/gopath/server.bin

Note Don't ask me why there are still four steps to install before gcc and go are installed, I don't know, I just got the wrong prompt to install

The source code is installed as follows

FROM centos
MAINTAINER yancoder@163.com
ENV GOROOT /usr/local/go
ENV GOPATH /data/gopath
ENV PATH $GOROOT/bin:$PATH
RUN yum install -y curl
RUN curl -s -o go.tar.gz https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz
RUN tar --remove-files -C /usr/local/ -zxf go.tar.gz
RUN mkdir -p /data/go
RUN ln -sv /usr/local/go/bin/go /bin
ADD src/ /data/gopath/src
ADD pkg/ /data/gopath/pkg
ADD test.go /data/gopath/test.go
WORKDIR /data/gopath
RUN go build -o server.bin test.go
CMD /data/gopath/server.bin

2. Create a mirror (note that there is a decimal point at the end)

docker build -t golang:v1.0 .

3. Create containers, and if you want to bind ports, do so in this step

docker run -d -p 80:80 golang:v1.0

4. Visit in an external browser~

Pit

1. If a dockerfile fails during operation, a useless image of <none>will be generated in images. Delete method is pasted from Baidu.

# Delete command:
docker rmi $(docker images | grep "none" | awk '{print $3}')
# The following steps can be taken after the last step has reported an error and there are containers that have not been stopped
# Stop Container
docker stop $(docker ps -a | grep "Exited" | awk '{print $1 }') 
# Delete:
docker rm $(docker ps -a | grep "Exited" | awk '{print $1 }')
# delete mirror
docker rmi $(docker images | grep "none" | awk '{print $3}')

2. Exit within the container of run will exit the container and cause the container to stop as well.The correct approach is to use exec with the following commands:

docker exec -it imageId /bin/bash

3. If you use dockerfile to directly ADD files into docker, nothing happens.But if you want to copy files from the current directory into the docker, first make sure the image is running (docker ps), then the container name in the docker cp command uses the name I circled.Delete and start stop containers use the previous ID

4. We have not found a way to map ports to running's containers yet. We have found some posts that seem to have configuration files to modify.For convenience, bind when creating containers~

summary

Docker is a tool application, but it's a bit like git. Think about the implementation process of docker in your head and you'll get a smooth grasp of it

There are also some commonly used docker commands, as well as file mapping, Click docker operation manual

Topics: Linux Docker yum CentOS curl