在Docker-Compose.yml中命令操作会自动在Entrypoint.sh中搜索



我正在学习docker,这是我从:

的项目中的docker-compose.yml文件的一部分
services:
  ...
  ...    
  redis:
    build: ./redis
    image: smartjoe:redis
    container_name: smartjoe--redis
    command: redis-server
    ports:
      - '9993:6379'
    volumes:
      - /redis
    volumes_from:
      - data 
  data:
    build: ./data
    image: smartjoe:data
    container_name: smartjoe--data
    volumes:
      - /data
      - /var/lib/mysql
      - /var/lib/redis/data
    command: tail -f /dev/null
  ...
  ...

redis:下的command: redis-server行中,我想知道redis-server来自哪里。搜索后,我能够发现它位于smartjoe--redis容器中的entrypoint.sh文件中:

/ # ls -la
total 68
drwxr-xr-x    1 root     root          4096 Mar 28 21:24 .
drwxr-xr-x    1 root     root          4096 Mar 28 21:24 ..
-rwxr-xr-x    1 root     root             0 Mar 28 21:24 .dockerenv
drwxr-xr-x    1 root     root          4096 Jun 28  2017 bin
drwxr-xr-x    4 redis    redis         4096 Aug  2 19:51 data
drwxr-xr-x    5 root     root           340 Aug  5 14:54 dev
lrwxrwxrwx    1 root     root            34 Jun 28  2017 entrypoint.sh -> usr/local/bin/docker-entrypoint.sh
drwxr-xr-x    1 root     root          4096 Mar 28 21:24 etc
drwxr-xr-x    1 root     root          4096 Jun 28  2017 home
drwxr-xr-x    1 root     root          4096 Jun 28  2017 lib
drwxr-xr-x    5 root     root          4096 Jun 25  2017 media
drwxr-xr-x    2 root     root          4096 Jun 25  2017 mnt
dr-xr-xr-x  229 root     root             0 Aug  5 14:54 proc
drwxr-xr-x    2 root     root          4096 Sep  7  2018 redis
drwx------    1 root     root          4096 Aug  5 18:14 root
drwxr-xr-x    2 root     root          4096 Jun 25  2017 run
drwxr-xr-x    1 root     root          4096 Jun 28  2017 sbin
drwxr-xr-x    2 root     root          4096 Jun 25  2017 srv
dr-xr-xr-x   13 root     root             0 Aug  1 16:00 sys
drwxrwxrwt    1 root     root          4096 Jun 28  2017 tmp
drwxr-xr-x    1 root     root          4096 Jun 28  2017 usr
drwxr-xr-x    1 root     root          4096 Jun 28  2017 var

entrypoint.sh的内容看起来像:

/ # cat entrypoint.sh 
#!/bin/sh
set -e
# first arg is `-f` or `--some-option`
# or first arg is `something.conf`
if [ "${1#-}" != "$1" ] || [ "${1%.conf}" != "$1" ]; then
    set -- redis-server "$@"
fi
# allow the container to be started with `--user`
if [ "$1" = 'redis-server' -a "$(id -u)" = '0' ]; then
    chown -R redis .
    exec su-exec redis "$0" "$@"
fi
exec "$@"

我的问题是:我看不到 docker-compose.yml脚本中任何地方引用的 entrypoint.sh,docker是否只是假设有这样的 entrypoint.sh文件并在文件中的 command:之后搜索关键词?

顺便说一句,Dockerfile很简单:

Bob@MacBook-Pro:~/smartjoe/smartjoe-local/docker/redis$ cat Dockerfile 
FROM redis:3.0-alpine
MAINTAINER smartjoe Engineering "engineering@smartjoe.com"
Bob@MacBook-Pro:~/smartjoe/smartjoe-local/docker/redis$ 

入口点将在图像中定义,smartjoe:redis。从dockerfile设置的默认值您可以在docker-compose.yml中覆盖。您可以通过检查图像,例如

来查看图像配置
docker image inspect smartjoe:redis

最新更新