This is a creation in Article, where the information may have evolved or changed.
That's what happened.
A person programmer, wrote a server with Golang, after finishing ... Not deployed:)
Yes, this man is me ...
I'm really going to die of laughter today.
Finally have the opportunity to use Golang in the company project development, the whole development process is quite hyper! However... When the small brother with the front end of the interface, the younger brother asked me when I can give the address on the line
(a face) forget about the line.
tend to write their own amateur Golang project directly go build and then drag to the server and then run it.
But this is the company project Ah!!! will give you FTP??? You can hit the server??? (as if hearing the voice of the DBA's little brother)
So... I found my DBA brother and asked how to publish it.
"You just pack an RPM or give a docker."
Ha?
Rpm? Are you sure it's not NPM?
Docker??? (I think I should have seen it two years ago.)
So humbly consulted the DBA small brother, "can trouble roughly with me about this rpm is how a play?" ”
"Well, you first ... *¥%#¥ and then $%......%%."
"Oh, well, I'll go check it out."
And then
And then I came back to learn about Docker 23333333333.
Fortunately, there's an old driver in the department.
Just let me get in the car.
Drive
First, we're going to start off with a docker
Mac Version: Https://www.docker.com/docker ...
You can turn on your Mac and it's proven to be installed, we're not repeating it.
After the installation, click on the cute little whale in the boot table.
Then, at the command line, enter
$ docker info
See a bunch of crap. Output proves successful Installation
We need to down a Linux image from the mirror market ~
Https://store.docker.com Search CentOS will see
Choose which version is completely familiar haha haha
See the specific version number at the command line execution
already exists because he's been pulling the record before he's written it. hahaha
View existing mirrors with Docker image after mounting the image
$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEcentos 7.2.1511 0a2bad7da9b5 5 months ago 195MB
Now let's get this image to run.
docker run -p 8888:80 --name godocker -e ENV="dev" -it 0a2bad7da9b5 /bin/bash
-P native Port number: The port number mapped to Docker (when the 8888 request of this machine is accessed, it goes to Docker's 80 port)
--name the name of the Docker instance (how to get started)
Environment variables for-e Docker
-V is similar to a soft chain, which maps a path of Docker to the entity path of the machine (specifically, it can be targeted Baidu OH)
The ID of the-it followed by the Docker image
Knock down the carriage return ~ Ah yo in!
No, don't worry, we're quitting first.
exit
Hurry up and build a go server
$ cd /xxx/xxx/xxx/xxx/xxx/gotest touch main.go vi main.go package main import "fmt" func main() { fmt.Println("hello word") }go build for linux (当然是伪代码啦) # 会生成一个跟目录同名的可执行文件 gotest# 将文件拷贝到docker镜像中$ docker cp /Users/wangboyan/development/golang/src/gotest/gotest godocker:/var/www# 然后进入docker中查看刚才的gotest是否存在 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESb2802801c24c 0a2bad7da9b5 "/bin/bash" 14 minutes ago Up 14 minutes 0.0.0.0:8888->80/tcp godocker docker exec -it b2802801c24c /bin/bash# 会发现我们成功进入了docker哦 $ cd /var/www$ ll$ gotest
Surprise ~ No Surprises ~
Completely expected ...
Execute the following our compiled executable file to see
At this time only want to ha ha haha haha
Now let's create a new image file with just the changes
# 先退出dockerexit$ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESb2802801c24c 0a2bad7da9b5 "/bin/bash" 14 minutes ago Up 14 minutes 0.0.0.0:8888->80/tcp godocker
We commit
turn containers into mirrors by command
$ docker commit -m "myself docker image" -a "holdno" 0a2bad7da9b5 holdno/centos-go:1.0.0 # 敲下回车后会得到以下结果 证明成功!sha256:554e840711c57bd4d2ede4a29a5c1dff3a711050c421ebfc38090d0f5a358b83 # 重新查看镜像信息 $ docker images REPOSITORY TAG IMAGE ID CREATED SIZEholdno/centos-go 1.0.0 554e840711c5 11 seconds ago 197MBcentos 7.2.1511 0a2bad7da9b5 5 months ago 195MB
Do you have! A new image is generated
Package (Save)
Your own Docker image is done (What did I do?) )
Let's pack this image.
After all, the DBA's little brother wants just a bag .
We can use save
and load
method, the former used to save the image of a tar file, the background from a tar file to restore a mirror
$ docker save -o /Users/wangboyan/development/docker/centos-go.v1.0.0.tar 554e840711c5
-o: Output to the file (note that this path must be a path that already exists!) )
Recovery (load)
# 删除刚刚打包过的镜像$ docker rmi 554e840711c5$ docker load < /Users/wangboyan/development/docker/centos-go.v1.0.0.tar Loading layer [==================================================>] 2.03MB/2.03MB $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE<none> <none> 554e840711c5 11 seconds ago 197MBcentos 7.2.1511 0a2bad7da9b5 5 months ago 195MB
I don't know why REPOSITORY and TAG have become none.
Now let's start the image we just imported.
$ docker run -it 554e840711c5 /bin/bash$ cd /var/www $ ll gotest # 有没有! 刚才cp进来的可执行文件还在!(这不是很正常吗) $ ./gotest hello world $
So you can just throw the Centos-go.v1.0.0.tar to the DBA's little brother?