docker - 在 dockerfile 中创建的卷未安装在容器中
问题描述
我想将 Firefox 锁定在 docker 容器中。为此,我创建了以下dockerfile
文件:
FROM debian:sid
RUN apt-get update && apt-get install -y \
firefox \
&& rm -rf /var/lib/apt/lists/*
RUN useradd \
--create-home \
--home-dir /home/morfitest/ \
--shell /bin/bash \
--uid 1000 \
--user-group \
morfitest
USER morfitest
ENV HOME /home/morfitest
RUN mkdir /home/morfitest/.mozilla
VOLUME ["/home/morfitest/.mozilla"]
WORKDIR /home/morfitest/
CMD /usr/bin/firefox
我还有一个docker-compose.yml
文件,如下所示:
version: '3.6'
services:
browser:
build:
context: .
dockerfile: dockerfile
image: firefox:morfitest
container_name: firefox
hostname: firefox
domainname: local
restart: "no"
volumes:
# - user_profile:/home/morfitest/.mozilla/
- /tmp/.X11-unix:/tmp/.X11-unix
environment:
- DISPLAY=$DISPLAY
logging:
driver: syslog
options:
syslog-address: "tcp://192.168.43.247:514"
tag: "firefox-morfitest"
networks:
default:
ipv4_address: 10.10.2.10
#volumes:
# user_profile:
networks:
default:
name: firefox
driver: bridge
ipam:
driver: default
config:
- subnet: 10.10.2.0/24
我已经读过,当您想以非 root 用户身份启动容器时,您不能volumes:
在docker-compose.yml
文件中使用,因为它在使用bind
. 因此,必须在dockerfile
文件中使用以下命令指定卷:
USER morfitest
RUN mkdir /home/morfitest/.mozilla
VOLUME ["/home/morfitest/.mozilla"]
容器构建和工作正常,但我无法弄清楚为什么在容器启动/启动时无法安装卷。
当我检查容器时,我可以看到以下内容:
$ docker container inspect firefox | grep vol
"Type": "volume",
"Source": "/media/Zami/docker/volumes/f2a4ee3dd34e2711b262f104e6b1aea6c07d107c38ec837c2baf11a39227c754/_data",
# ls -al /media/Zami/docker/volumes/f2a4ee3dd34e2711b262f104e6b1aea6c07d107c38ec837c2baf11a39227c754/_data
total 20
drwxr-xr-x 5 morfik morfik 4096 2019-01-21 09:30:57 ./
drwxr-xr-x 3 root root 4096 2019-01-21 09:30:55 ../
drwx------ 2 morfik morfik 4096 2019-01-21 09:30:57 extensions/
drwx------ 5 morfik morfik 4096 2019-01-21 09:30:57 firefox/
drwx------ 2 morfik morfik 4096 2019-01-21 09:30:57 systemextensionsdev/
所以该卷存在并且有一些内容,但是它不起作用。CMD
当我在文件中使用以下内容时dockerfile
:
CMD ls -al /home/morfitest/ && ls -al /home/morfitest/.mozilla
要实际查看容器启动/启动时卷的内容是否可见,我只能看到:
firefox-morfitest[61138]: total 24
firefox-morfitest[61138]: drwxr-xr-x 1 morfitest morfitest 4096 Jan 21 08:05 .
firefox-morfitest[61138]: drwxr-xr-x 1 root root 4096 Jan 21 08:05 ..
firefox-morfitest[61138]: -rw-r--r-- 1 morfitest morfitest 220 Jun 17 2018 .bash_logout
firefox-morfitest[61138]: -rw-r--r-- 1 morfitest morfitest 3526 Jun 17 2018 .bashrc
firefox-morfitest[61138]: drwxr-xr-x 2 morfitest morfitest 4096 Jan 21 08:05 .mozilla
firefox-morfitest[61138]: -rw-r--r-- 1 morfitest morfitest 807 Jun 17 2018 .profile
firefox-morfitest[61138]: total 8
firefox-morfitest[61138]: drwxr-xr-x 2 morfitest morfitest 4096 Jan 21 08:05 .
firefox-morfitest[61138]: drwxr-xr-x 1 morfitest morfitest 4096 Jan 21 08:05 ..
该目录.mozilla
具有正确的权限,但它是空的。那么如何挂载卷呢?
解决方案
基本上配置文件没问题,问题出在被注释掉的行中。实际上应该删除哈希并且设置工作正常。
但是当我一开始尝试这样做时,音量被忽略了——由于一些视觉错误,以下警告的某些部分没有显示:
WARNING: Service "browser" is using volume "/home/morfitest/.mozilla" from the
previous container. Host mapping "docker-firefox_user_profile" has no effect.
Remove the existing containers (with docker-compose rm browser)
我根据需要删除了容器,现在,它创建了一个具有持久名称的卷:docker-firefox_user_profile
而不是哈希。现在当我这样做时down
/up
它使用卷而不是创建一个新卷。这解决了我的问题。
推荐阅读
- html - 如何确定网格项内容的基线?
- javascript - 根据 Squarespace 中选中/未选中的选项显示/隐藏表单字段
- python-3.x - 轴标签在我的图中不断被切断
- c++ - 将节点插入AVL树递归python混淆
- javascript - Django,如何在 JavaScript 中使用 fetch 和 PUT 更新我的以下列表?
- aws-lambda - 连接到同一 VPC 中的 Redis Elasticache 时的 AWS Lambda 超时
- gem5 - 是否可以仅在 python 中创建我的对象并通过 gem5 端口连接到现有的 gem5 对象?
- javascript - 使用flask、python和sqlite在图标单击时从html表中删除行
- php - 快速将数据从 websocket 管道/摄取到弹性搜索中,以避免缓冲区过载
- c++ - 在派生类中覆盖运算符重载行为而不单独手动重写和隐藏每个运算符的标准方法是什么?