如何编译n9e-server服务并做成docker镜像呢?

Viewed 57
# cd nightingale/
# ll
total 31628
drwxr-xr-x 3 197609 197121     4096 Mar  3 15:21 doc
drwxr-xr-x 9 197609 197121     4096 Mar 29 19:19 docker
drwxr-xr-x 7 197609 197121     4096 Mar 15 21:18 etc
-rwxr-xr-x 1 197609 197121      331 Mar  3 15:21 fe.sh
-rw-r--r-- 1 197609 197121     3892 Mar  3 16:08 go.mod
-rw-r--r-- 1 197609 197121    73336 Mar  3 16:08 go.sum
-rw-r--r-- 1 197609 197121    11834 Mar  3 15:21 LICENSE
-rw-r--r-- 1 197609 197121     1722 Mar  3 15:21 Makefile
-rw-r--r-- 1 197609 197121     4414 Mar  3 15:21 README_EN.md
-rw-r--r-- 1 197609 197121    10044 Mar  3 15:21 README.md
drwxr-xr-x 8 197609 197121     4096 Mar 29 17:46 src

# make all
生成 n9e 二进制文件


# cat docker/Dockerfile
FROM python:2.7.8-slim
#FROM python:2
#FROM ubuntu:21.04

WORKDIR /app
ADD n9e /app
ADD http://download.flashcat.cloud/wait /wait
RUN mkdir -p /app/pub && chmod +x /wait
ADD pub /app/pub/
RUN chmod +x n9e

EXPOSE 19000
EXPOSE 18000

CMD ["/app/n9e", "-h"]


# cd docker/
# docker build -t n9e:v1 .
Sending build context to Docker daemon  63.49kB
Step 1/10 : FROM python:2.7.8-slim
2.7.8-slim: Pulling from library/python
Image docker.io/library/python:2.7.8-slim uses outdated schema1 manifest format. Please upgrade to a schema2 image for better future compatibility. More information at https://docs.docker.com/registry/spec/deprecated-schema-v1/
a3ed95caeb02: Pull complete
5d3df020ecd3: Pull complete
b90912281233: Pull complete
c1315240434c: Pull complete
1706117b37b1: Pull complete
Digest: sha256:1380cf6534a123cd73cf97b9f02c702eb74c4564b156d56df4bba034ffa89d9a
Status: Downloaded newer image for python:2.7.8-slim
 ---> 7ec57078ecb6
Step 2/10 : WORKDIR /app
 ---> Running in b659794229d9
Removing intermediate container b659794229d9
 ---> 48a209621c1f
Step 3/10 : ADD n9e /app
ADD failed: stat /var/lib/docker/tmp/docker-builder987839092/n9e: no such file or directory

如上所示,当我本地编译生成n9e二进制文件后,猜测是通过 docker/Dockerfile 进行编译。
但是 ADD pub /app/pub/ 这一行中有个 pub 文件,这是pub文件怎么获得呢?
还是说如果进行镜像制作并不是使用此文件?

2 Answers

这样操作的对吗?

# mkdir pub
# cd docker
# sh build.sh v1
tag: v1
Sending build context to Docker daemon  32.32MB
Step 1/10 : FROM python:2.7.8-slim
 ---> 7ec57078ecb6
Step 2/10 : WORKDIR /app
 ---> Using cache
 ---> 48a209621c1f
Step 3/10 : ADD n9e /app
 ---> Using cache
 ---> d1c1635f1002
Step 4/10 : ADD http://download.flashcat.cloud/wait /wait
Downloading [==================================================>]  399.1kB/399.1kB
 ---> Using cache
 ---> 869850d9877a
Step 5/10 : RUN mkdir -p /app/pub && chmod +x /wait
 ---> Using cache
 ---> b97b784dae23
Step 6/10 : ADD pub /app/pub/
 ---> bd48b78df386
Step 7/10 : RUN chmod +x n9e
 ---> Running in a82289832674
Removing intermediate container a82289832674
 ---> 73df0303c893
Step 8/10 : EXPOSE 19000
 ---> Running in 1848384b2df1
Removing intermediate container 1848384b2df1
 ---> 0a1a7d2a9be3
Step 9/10 : EXPOSE 18000
 ---> Running in 1e28188a3ce6
Removing intermediate container 1e28188a3ce6
 ---> fa11facdba76
Step 10/10 : CMD ["/app/n9e", "-h"]
 ---> Running in cf1a2ca21f01
Removing intermediate container cf1a2ca21f01
 ---> 57da500dfdf4
Successfully built 57da500dfdf4
Successfully tagged nightingale:v1
The push refers to repository [docker.io/ulric2019/nightingale]
... ...

# docker images | grep v1
nightingale                                                              v1                     57da500dfdf4        About a minute ago   307MB