docker-compose无法切换用户

问题描述

jupyter:
    image: flink:1.19-py
    privileged: true
    user: root
    ports:
      - "9999:8888"
    volumes:
      - /data/docker_data/jupyter:/work
    command: sh -c "cd / && jupyter notebook --ip 0.0.0.0 --port 8888 --allow-root --NotebookApp.password=sha1:6587feaef3b1:6b243404e4cfaafe611fdf494ee71fdaa8c4a563"
    networks:
      - flink-net

为什么容器内执行的命令用户是flink

root@22c47eeae6cf:/opt/flink# ps -ef
UID          PID    PPID  C STIME TTY          TIME CMD
flink          1       0  0 06:10 ?        00:00:00 sh -c cd / && jupyter notebook --ip 0.0.0.0 --port 8888 --allow-root --NotebookApp.password=sha1:6587feaef3b1:6b243404e4cfaafe611fdf494ee71fdaa8c4a563
flink         78       1  0 06:10 ?        00:00:01 /usr/bin/python3 /usr/local/bin/jupyter-notebook --ip 0.0.0.0 --port 8888 --allow-root --NotebookApp.password=sha1:6587feaef3b1:6b243404e4cfaafe611fdf494ee

原因分析

docker-compose.yml 中指定了 command,但是没有指定 entrypoint
实际启动容器时仍使用了镜像里的entry-point,command只是作为entry-point.sh 脚本的参数

在这里插入图片描述
在entry-point脚本中切换了用户
在这里插入图片描述

解决方案

修改docker-compose.yml 中的entrypoint

  jupyter:
    image: flink:1.19-py
    privileged: true
    user: root
    ports:
      - "9999:8888"
    volumes:
      - /data/docker_data/jupyter:/work
    entrypoint: sh
    command:
      - "-c"
      - "cd / && jupyter notebook --ip 0.0.0.0 --port 8888 --allow-root --NotebookApp.password=sha1:6587feaef3b1:6b243404e4cfaafe611fdf494ee71fdaa8c4a563"
    networks:
      - flink-net

结果正确

[root@localhost data]# docker exec -it data_jupyter_1 bash
root@95fbecd2211a:/opt/flink# ps -ef
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 06:44 ?        00:00:00 sh -c cd / && jupyter notebook --ip 0.0.0.0 --port 8888 --allow-root --NotebookApp.password=sha1:6587feaef3b1:6b243404e4cfaafe611fdf494ee71fdaa8c4a563
root           7       1  6 06:44 ?        00:00:01 /usr/bin/python3 /usr/local/bin/jupyter-notebook --ip 0.0.0.0 --port 8888 --allow-root --NotebookApp.password=sha1:6587feaef3b1:6b243404e4cfaafe611fdf494eeroot          10       0  0 06:44 pts/0    00:00:00 bash
root          18      10  0 06:44 pts/0    00:00:00 ps -ef
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

颹蕭蕭

白嫖?

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值