DOCKER学习_013:Dockerfile配置指令ENTRYPOINT详解
前面已经介绍了一些Dockerfile的一些指令,对于ENTRYPOINT和CMD也有介绍实验
一 ENTRYPOINT和CMD配置使用
ENTRYPOINT相当于CMD,是配置容器后的一个指令,但是他不会被提docker run供的参数覆盖,每个Dockerfile只能有一个ENTRYPOINT,如果指定了多个,只有最后一个被执行,而且一定会被执行
1.1 不指定CMD,使用子进程
例如,指定ENTRYPOINT,不指定CMD,看效果
FROM centos:7
LABEL darren darren@gmail.com ENV TZ "Asia/Shanghai" ADD keys.tar.gz /
RUN yum -y install openssh-server \
&& useradd natash \
&& echo "redhat"|passwd --stdin natash \
&& echo "redhat"|passwd --stdin root \
&& ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N ''\
&& ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' \
&& ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N '' \
&& echo "$TZ"\
&& cp /keys/ssh_host_ecdsa_key /keys/ssh_host_ed25519_key /keys/ssh_host_rsa_key /tmp/
#ADD keys/ssh_host_ecdsa_key /tmp/ssh_host_ecdsa_key
#ADD keys/ssh_host_ed25519_key /tmp/ssh_host_ed25519_key
#COPY keys/ssh_host_rsa_key /tmp/ssh_host_rsa_key #COPY keys.tar.gz /keys.tar.gz
#RUN tar -zxf /keys.tar.gz && cp /keys/ssh_host_ecdsa_key /keys/ssh_host_ed25519_key /keys/ssh_host_rsa_key /tmp/
#RUN cp /keys/ssh_host_ecdsa_key /keys/ssh_host_ed25519_key /keys/ssh_host_rsa_key ./ EXPOSE 22 80
#CMD ["/usr/sbin/sshd", "-D"]
ENTRYPOINT /usr/sbin/sshd
#CMD /usr/sbin/sshd -D
上面执行之后,我们在运行容器加一个参数-D
[root@docker-server3 openssh]# docker build -t openssh:v1.8 .
[root@docker-server3 openssh]# docker run -d openssh:v1.8 -D
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
601a915564cd openssh:v1.8 "/bin/sh -c /usr/sbi…" 8 seconds ago Exited (0) 6 seconds ago nervous_almeida #没有运行成功
915f9a1854c6 openssh:v1.7 "/bin/sh -c '/usr/sb…" 22 minutes ago Up 22 minutes 22/tcp, 80/tcp practical_margulis
131649a5d893 openssh:v1.6 "/usr/sbin/sshd -D" 29 minutes ago Up 29 minutes 22/tcp, 80/tcp zealous_poincare
e0847916fa35 nginx "nginx -g 'daemon of…" 37 minutes ago Up 37 minutes 80/tcp pedantic_blackburn
41e2d69f3503 openssh:v1.5 "/usr/sbin/sshd -D" 7 hours ago Up 7 hours objective_sinoussi
db351e66fc63 openssh:v1.4 "/usr/sbin/sshd -D" 8 hours ago Up 8 hours nifty_curran
f6a4ebe048cd openssh:v1.4 "/bin/bash" 8 hours ago Exited (0) 8 hours ago adoring_archimedes
fd2c629a2b3c openssh:v1.3 "/usr/sbin/sshd -D" 2 days ago Up 2 days
是因为ENTRYPOINT /usr/sbin/sshd这个语法导致的,这样写,执行的过程是/bin/bash -c "/usr/sbin/sshd" -D ,是没有办法执行成功的
1.2 直接使用进程
修改
FROM centos:7
LABEL darren darren@gmail.com ENV TZ "Asia/Shanghai" ADD keys.tar.gz /
RUN yum -y install openssh-server \
&& useradd natash \
&& echo "redhat"|passwd --stdin natash \
&& echo "redhat"|passwd --stdin root \
&& ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N ''\
&& ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' \
&& ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N '' \
&& echo "$TZ"\
&& cp /keys/ssh_host_ecdsa_key /keys/ssh_host_ed25519_key /keys/ssh_host_rsa_key /tmp/
#ADD keys/ssh_host_ecdsa_key /tmp/ssh_host_ecdsa_key
#ADD keys/ssh_host_ed25519_key /tmp/ssh_host_ed25519_key
#COPY keys/ssh_host_rsa_key /tmp/ssh_host_rsa_key #COPY keys.tar.gz /keys.tar.gz
#RUN tar -zxf /keys.tar.gz && cp /keys/ssh_host_ecdsa_key /keys/ssh_host_ed25519_key /keys/ssh_host_rsa_key /tmp/
#RUN cp /keys/ssh_host_ecdsa_key /keys/ssh_host_ed25519_key /keys/ssh_host_rsa_key ./ EXPOSE 22 80
#CMD ["/usr/sbin/sshd", "-D"]
ENTRYPOINT ["/usr/sbin/sshd"]
#CMD /usr/sbin/sshd -D
这种写法,容器执行就是/usr/sbin/sshd -D,就可以正常运行了
[root@docker-server3 openssh]# docker build -t openssh:v1.8 .
[root@docker-server3 openssh]# docker run -d openssh:v1.8 -D
[root@docker-server3 openssh]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
88396812fa0a openssh:v1.8 "/usr/sbin/sshd -D" 6 seconds ago Up 5 seconds 22/tcp, 80/tcp romantic_allen
601a915564cd 1613f91bbfb3 "/bin/sh -c /usr/sbi…" 8 minutes ago Exited (0) 8 minutes ago nervous_almeida
915f9a1854c6 openssh:v1.7 "/bin/sh -c '/usr/sb…" 30 minutes ago Up 30 minutes 22/tcp, 80/tcp practical_margulis
131649a5d893 openssh:v1.6 "/usr/sbin/sshd -D" 37 minutes ago Up 37 minutes 22/tcp, 80/tcp zealous_poincare
e0847916fa35 nginx "nginx -g 'daemon of…" 46 minutes ago Up 46 minutes 80/tcp pedantic_blackburn
41e2d69f3503 openssh:v1.5 "/usr/sbin/sshd -D" 7 hours ago Up 7 hours objective_sinoussi
db351e66fc63 openssh:v1.4 "/usr/sbin/sshd -D" 8 hours ago Up 8 hours nifty_curran
f6a4ebe048cd openssh:v1.4 "/bin/bash" 8 hours ago Exited (0) 8 hours ago adoring_archimedes
fd2c629a2b3c openssh:v1.3 "/usr/sbin/sshd -D" 2 days ago Up 2 days
ENTRYPOINT运行在CMD之前,所以必须写在CMD前面
同时,一些容器可以直接添加参数,但是不能使用完整的指令,就是因为生成镜像的时候,直接使用的ENTRYPOINT这个参数
1.3 加上CMD参数执行
FROM centos:7
LABEL darren darren@gmail.com ENV TZ "Asia/Shanghai" ADD keys.tar.gz /
RUN yum -y install openssh-server \
&& useradd natash \
&& echo "redhat"|passwd --stdin natash \
&& echo "redhat"|passwd --stdin root \
&& ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N ''\
&& ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' \
&& ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N '' \
&& echo "$TZ"\
&& cp /keys/ssh_host_ecdsa_key /keys/ssh_host_ed25519_key /keys/ssh_host_rsa_key /tmp/
#ADD keys/ssh_host_ecdsa_key /tmp/ssh_host_ecdsa_key
#ADD keys/ssh_host_ed25519_key /tmp/ssh_host_ed25519_key
#COPY keys/ssh_host_rsa_key /tmp/ssh_host_rsa_key #COPY keys.tar.gz /keys.tar.gz
#RUN tar -zxf /keys.tar.gz && cp /keys/ssh_host_ecdsa_key /keys/ssh_host_ed25519_key /keys/ssh_host_rsa_key /tmp/
#RUN cp /keys/ssh_host_ecdsa_key /keys/ssh_host_ed25519_key /keys/ssh_host_rsa_key ./ EXPOSE 22 80
#CMD ["/usr/sbin/sshd", "-D"]
ENTRYPOINT ["/usr/sbin/sshd"]
CMD ["-D"]
#CMD /usr/sbin/sshd -D
上面的操作,ENTRYPOINT和CMD一个简单的配合使用
二 ENTRYPOINT的高级用法
删掉所有的容器
2.1 写一个简单的nginx的Dockerfile
[root@docker-server3 openssh]# mkdir /nginx
[root@docker-server3 openssh]# cd /nginx
[root@docker-server3 httpd]# vi Dockerfile
FROM centos:7 RUN yum install -y wget && wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo \
&& yum -y install nginx EXPOSE 80
CMD ["nginx","-g","daemon off;"]
[root@docker-server3 nginx]# docker build -t nginx:v1.1 .
Sending build context to Docker daemon 2.048kB
Step 1/4 : FROM centos:7
---> 5e35e350aded
Step 2/4 : RUN yum install -y wget && wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo && yum -y install nginx
---> Using cache
---> 6cd0272f03af
Step 3/4 : EXPOSE 80
---> Running in d4b38097012d
Removing intermediate container d4b38097012d
---> 2059882b01c1
Step 4/4 : CMD ["nginx","-g","daemon off;"]
---> Running in 7bb92490efc5
Removing intermediate container 7bb92490efc5
---> 68354cda3d7b
Successfully built 68354cda3d7b
Successfully tagged nginx:v1.1
[root@docker-server3 nginx]# docker run -d nginx:v1.1
666927b25d2f081ce70aca3719c407cce7db6d2ba200b1241d78bf7455e1dc6b
[root@docker-server3 nginx]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
666927b25d2f nginx:v1.1 "nginx -g 'daemon of…" 4 seconds ago Up 2 seconds 80/tcp xenodochial_austin
访问这个端口
[root@docker-server3 nginx]# docker inspect 666927b25d2f|grep IP
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "192.168.0.9",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"IPAMConfig": null,
"IPAddress": "192.168.0.9",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
[root@docker-server3 nginx]# curl http://192.168.0.9
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
2.2 出现403错误,进入容器检查
[root@docker-server3 nginx]# docker exec -it 666927b25d2f /bin/bash
[root@666927b25d2f /]# ps -ef|grep nginx
root 1 0 0 21:10 ? 00:00:00 nginx: master process nginx -g daemon off;
nginx 6 1 0 21:10 ? 00:00:00 nginx: worker process
nginx 7 1 0 21:10 ? 00:00:00 nginx: worker process
nginx 8 1 0 21:10 ? 00:00:00 nginx: worker process
nginx 9 1 0 21:10 ? 00:00:00 nginx: worker process
root 25 10 0 21:15 pts/0 00:00:00 grep --color=auto nginx
[root@666927b25d2f /]# yum -y install net-tools
[root@666927b25d2f /]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1/nginx: master pro
tcp6 0 0 :::80 :::* LISTEN 1/nginx: master pro
[root@666927b25d2f /]# cd /usr/share/nginx/html/
[root@666927b25d2f html]# ll
[root@666927b25d2f html]# rm -rf index.html
[root@666927b25d2f html]# echo "just a test" > index.html
[root@666927b25d2f html]# curl http://127.0.0.1
just a test
[root@666927b25d2f html]# exit
exit
[root@docker-server3 nginx]# curl http://192.168.0.9
2.3 根据以上信息修改Dockerfile文件
FROM centos:7
WORKDIR /usr/share/nginx/html
RUN yum install -y wget && wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo \
&& yum -y install nginx && rm -rf index.html && echo "nginx in custom docker" > index.html EXPOSE 80
CMD ["nginx","-g","daemon off;"]
[root@docker-server3 nginx]# docker build -t nginx:v1.2 .
[root@docker-server3 nginx]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
55645329c490 nginx:v1.2 "nginx -g 'daemon of…" 4 seconds ago Up 3 seconds 80/tcp intelligent_carson
666927b25d2f nginx:v1.1 "nginx -g 'daemon of…" 18 minutes ago Up 18 minutes 80/tcp xenodochial_austin
[root@docker-server3 nginx]# docker inspect 55645329c490|grep IP
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "192.168.0.2",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"IPAMConfig": null,
"IPAddress": "192.168.0.2",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
[root@docker-server3 nginx]# curl http://192.168.0.2
需求,根据这个基础的ngix镜像,传递不同的参数,使用不同的代码,访问不同的网站
2.4 使用-e传递参数
[root@docker-server3 nginx]# docker run -d -e "index=docker" -e "a=b" nginx:v1.2
[root@docker-server3 nginx]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
593a35ccbbf9 nginx:v1.2 "nginx -g 'daemon of…" 11 seconds ago Up 10 seconds 80/tcp cool_clarke
55645329c490 nginx:v1.2 "nginx -g 'daemon of…" 6 minutes ago Up 6 minutes 80/tcp intelligent_carson
666927b25d2f nginx:v1.1 "nginx -g 'daemon of…" 24 minutes ago Up 24 minutes 80/tcp xenodochial_austin
2.5 查看传递参数的效果
[root@docker-server3 nginx]# docker exec -it 593a35ccbbf9 /bin/bash
[root@593a35ccbbf9 html]# env
HOSTNAME=593a35ccbbf9
TERM=xterm
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
index=docker
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/usr/share/nginx/html
a=b
SHLVL=1
HOME=/root
_=/usr/bin/env
已经传递了参数
2.6 构建ENTRYPOINT使用脚本
[root@docker-server3 nginx]# vi build.sh
#!/bin/sh indexfile=/usr/share/nginx/html/index.html if [ ! -z "$index" ];then
echo "nginx in $index" > $indexfile
else
echo "just a test" > $indexfile
fi
2.7 修改Dockerfile,添加ENTRYPOINT指令
[root@docker-server3 nginx]# cat Dockerfile
FROM centos:7
WORKDIR /usr/share/nginx/html
ADD build.sh /build.sh
RUN yum install -y wget && wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo \
&& yum -y install nginx && rm -rf index.html && echo "nginx in custom docker" > index.html && chmod +x /build.sh EXPOSE 80 ENTRYPOINT ["/build.sh"]
CMD ["nginx","-g","daemon off;"]
[root@docker-server3 nginx]# docker build -t nginx:v1.3 .
[root@docker-server3 nginx]# docker run -d nginx:v1.3
[root@docker-server3 nginx]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9de02f005f66 nginx:v1.3 "/build.sh nginx -g …" 3 seconds ago Exited (0) 2 seconds ago flamboyant_poincare
593a35ccbbf9 nginx:v1.2 "nginx -g 'daemon of…" 25 minutes ago Up 25 minutes 80/tcp cool_clarke
55645329c490 nginx:v1.2 "nginx -g 'daemon of…" 31 minutes ago Up 31 minutes 80/tcp intelligent_carson
666927b25d2f nginx:v1.1 "nginx -g 'daemon of…" 49 minutes ago Up 49 minutes 80/tcp xenodochial_austin
这样操作的问题,是因为ENTRYPOINT这个指令存在的时候,CMD就会变成/build.sh脚本的一个参数,但是这个脚本不需要参数,就会错误
2.8 修改build.sh,修正错误后结果
[root@docker-server3 nginx]# vi build.sh
#!/bin/sh indexfile=/usr/share/nginx/html/index.html if [ ! -z "$index" ];then
echo "nginx in $index" > $indexfile
else
echo "just a test" > $indexfile
fi exec "$@"
[root@docker-server3 nginx]# docker build -t nginx:v1.4 .
[root@docker-server3 nginx]# docker run -d nginx:v1.4
0fef39ec7ffd76bb7b8fb45116be2b3beea08e82c66ffc8fec66d49188f9af11
[root@docker-server3 nginx]# docker inspect 0fef39ec7ffd|grep IP
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "192.168.0.4",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"IPAMConfig": null,
"IPAddress": "192.168.0.4",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
[root@docker-server3 nginx]# curl http://192.168.0.4
[root@docker-server3 nginx]# docker run -d -e "index=aaa" nginx:v1.4
3b26204c8758cb0b104be1106dd33c2ae29430db3af59e49209cd0357aaae3df
[root@docker-server3 nginx]# docker inspect 3b26204c8758|grep IP
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "192.168.0.5",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"IPAMConfig": null,
"IPAddress": "192.168.0.5",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
[root@docker-server3 nginx]# curl http://192.168.0.5
ENTRYPOINT参数介绍到这里,关于dockefile文件的编写学习,可以看官方https://hub.docker.com
2.10 官方Dockerfile介绍
根据官方,看一个mysql的dockerfile文件
https://hub.docker.com/_/mysql
点击会得到一个连接
进入,得到官方的DOCKERFILE
https://github.com/docker-library/mysql/blob/6659750146b7a6b91a96c786729b4d482cf49fe6/8.0/Dockerfile
FROM debian:stretch-slim # add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r mysql && useradd -r -g mysql mysql RUN apt-get update && apt-get install -y --no-install-recommends gnupg dirmngr && rm -rf /var/lib/apt/lists/* # add gosu for easy step-down from root
ENV GOSU_VERSION 1.7
RUN set -x \
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
&& gpgconf --kill all \
&& rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu \
&& gosu nobody true \
&& apt-get purge -y --auto-remove ca-certificates wget RUN mkdir /docker-entrypoint-initdb.d RUN apt-get update && apt-get install -y --no-install-recommends \
# for MYSQL_RANDOM_ROOT_PASSWORD
pwgen \
# for mysql_ssl_rsa_setup
openssl \
# FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db:
# File::Basename
# File::Copy
# Sys::Hostname
# Data::Dumper
perl \
&& rm -rf /var/lib/apt/lists/* RUN set -ex; \
# gpg: key 5072E1F5: public key "MySQL Release Engineering <mysql-build@oss.oracle.com>" imported
key='A4A9406876FCBD3C456770C88C718D3B5072E1F5'; \
export GNUPGHOME="$(mktemp -d)"; \
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
gpg --batch --export "$key" > /etc/apt/trusted.gpg.d/mysql.gpg; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME"; \
apt-key list > /dev/null ENV MYSQL_MAJOR 8.0
ENV MYSQL_VERSION 8.0.18-1debian9 RUN echo "deb http://repo.mysql.com/apt/debian/ stretch mysql-${MYSQL_MAJOR}" > /etc/apt/sources.list.d/mysql.list # the "/var/lib/mysql" stuff here is because the mysql-server postinst doesn't have an explicit way to disable the mysql_install_db codepath besides having a database already "configured" (ie, stuff in /var/lib/mysql/mysql)
# also, we set debconf keys to make APT a little quieter
RUN { \
echo mysql-community-server mysql-community-server/data-dir select ''; \
echo mysql-community-server mysql-community-server/root-pass password ''; \
echo mysql-community-server mysql-community-server/re-root-pass password ''; \
echo mysql-community-server mysql-community-server/remove-test-db select false; \
} | debconf-set-selections \
&& apt-get update && apt-get install -y mysql-community-client="${MYSQL_VERSION}" mysql-community-server-core="${MYSQL_VERSION}" && rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql /var/run/mysqld \
&& chown -R mysql:mysql /var/lib/mysql /var/run/mysqld \
# ensure that /var/run/mysqld (used for socket and lock files) is writable regardless of the UID our mysqld instance ends up having at runtime
&& chmod 777 /var/run/mysqld VOLUME /var/lib/mysql
# Config files
COPY config/ /etc/mysql/
COPY docker-entrypoint.sh /usr/local/bin/
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
ENTRYPOINT ["docker-entrypoint.sh"] #ENTRYPOINT指令 EXPOSE 3306 33060
CMD ["mysqld"]
https://github.com/docker-library/mysql/tree/6659750146b7a6b91a96c786729b4d482cf49fe6/8.0
查看docker-entrypoint.sh
Dockerfile学习到这里
博主声明:本文的内容来源主要来自誉天教育晏威老师,由本人实验完成操作验证,需要的博友请联系誉天教育(http://www.yutianedu.com/),获得官方同意或者晏老师(https://www.cnblogs.com/breezey/)本人同意即可转载,谢谢!
DOCKER学习_013:Dockerfile配置指令ENTRYPOINT详解的更多相关文章
- DOCKER学习_012:Dockerfile配置指令详解
1 Dockerfile结构 基础镜像信息 镜像操作指令 容器启动时执行指令 2 FROM 指定基础镜像,用于继承其他镜像使用的 FROM ubuntu:14.06 FROM centos FROM ...
- [转帖]Docker学习之Dockerfile命令详解
Docker学习之Dockerfile命令详解 https://it.baiked.com/system/docker/2436.html 图挺好的 前言 之前,制作镜像的伪姿势搭建已经见过了,今天介 ...
- CentOS 6.3下Samba服务器的安装与配置方法(图文详解)
这篇文章主要介绍了CentOS 6.3下Samba服务器的安装与配置方法(图文详解),需要的朋友可以参考下 一.简介 Samba是一个能让Linux系统应用Microsoft网络通讯协议的软件, ...
- Eclipse进行C/C++开发——Eclipse+CDT+MinGW的配置与使用详解
http://hi.baidu.com/ltb6w/item/3a51f11926fda60ce75c361d Eclipse进行C/C++开发——Eclipse+CDT+MinGW的配置与使用详解 ...
- SSI指令使用详解(转)
什么是 SHTML使用SSI(Server Side Include)的html文件扩展名,SSI(Server Side Include),通常称为“服务器端嵌入”或者叫“服务器端包含”,是一种类似 ...
- ASP.NET MVC 5 学习教程:生成的代码详解
原文 ASP.NET MVC 5 学习教程:生成的代码详解 起飞网 ASP.NET MVC 5 学习教程目录: 添加控制器 添加视图 修改视图和布局页 控制器传递数据给视图 添加模型 创建连接字符串 ...
- MySql绿色版配置及使用详解
原文:MySql绿色版配置及使用详解 最近在做项目开发时用到了MySql数据库,在看了一些有关MySql的文章后,很快就上手使用了.在使用的过程中还是出现了一些问题,因为使用的是绿色免安装版的MySq ...
- 全网最详细的Windows系统里PLSQL Developer 64bit安装之后的一些配置(图文详解)
不多说,直接上干货! 注意的是: 本地若没有安装Oracle服务端,Oracle server服务端64位,是远程连接,因此本地配置PLSQL Developer64位. PLSQL Develope ...
- java环境配置及原理详解
java环境配置及原理详解 1.java跨平台的本质 我们谈到java,总是提到跨平台这个词.那么java语言是怎么实现跨平台的呢? 我们编写的java代码不是直接让windows系统读取解析,而是在 ...
随机推荐
- HarmonyOS三方件开发指南(17)-BottomNavigationBar
目录: 1.引言 2.功能介绍 3.BottomNavigationBar使用指南 4.BottomNavigationBar开发指南 5.<HarmonyOS三方件开发指南>文章合集 引 ...
- Webpack的基本配置和打包与介绍(二)
1. 前言 在上一章中我们学习到了webpack的基本安装配置和打包,我们这一章来学学如何使用loader和plugins 如果没看第一章的这里有传送门 2. Loader 2.1 什么是loader ...
- 如何在IDEA中进行时序图分析
方法一: 使用插件 SequenceDiagram (系统自动生成) 使用方法: 下载插件,我们可以在 Plugins 中找到 选中线程方法名,然后右键就可以创建此方法的时序图了 参数设置 生成效果以 ...
- 痞子衡嵌入式:在i.MXRT启动头FDCB里使能串行NOR Flash的DTR模式
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是在FDCB里使能串行NOR Flash的DTR模式. 前两篇文章 <IS25WP系列Dummy Cycle设置> 与 < ...
- Nginx的进程管理与重载原理
目录 进程结构图 信号量管理 Linux的信号量管理机制 利用信号量管理Nginx进程 配置文件重载原理 进程结构图 Nginx是多进程结构,多进程结构设计是为了保证Nginx的高可用高可靠,包含: ...
- Docker下MySQL的安装
1 概述 本文讲述了如何利用Docker去安装MySQL,以及MySQL自定义配置文件的相关设置. 2 安装Docker 首先安装Docker并开启服务: systemctl start docker ...
- .Net Core 集成 Kafka
最近维护的一个系统并发有点高,所以想引入一个消息队列来进行削峰.考察了一些产品,最终决定使用kafka来当做消息队列.以下是关于kafka的一些知识的整理笔记. kafka kafka 是分布式流式平 ...
- 1113 Integer Set Partition
Given a set of N (>) positive integers, you are supposed to partition them into two disjoint sets ...
- PE文件附加数据感染之Worm.Win32.Agent.ayd病毒分析
一.基本信息 样本名称:1q8JRgwDeGMofs.exe 病毒名称:Worm.Win32.Agent.ayd 文件大小:165384 字节 文件MD5:7EF5D0028997CB7DD3484A ...
- Python中sys模块的使用
目录 sys模块 sys.argv() sys.exit(0) sys.path sys.modules sys模块负责程序与python解释器的交互,提供了一系列的函数和变量,用于操控python的 ...