我正在尝试学习docker。所以我试图创建一个archlinux映像。目前我不担心大小。但是我对如何继续使用它作为我的项目开发感到困惑。我的目标是分别为我的不同项目创建和使用不同的archlinux映像。
1) shift to root in terminal
2) mkdir archlinux
3) pacstrap -i -c -d ./archlinux base
4) echo 'en_US.UTF-8 UTF-8' > ./archlinux/etc/locale.gen
5) arch-chroot ./archlinux locale-gen
6) echo 'LANG=en_US.UTF-8' > ./archlinux/etc/locale.conf
现在,archlinux文件夹的总大小为899 MB.
现在我正尝试将其作为docker映像导入
cd archlinux
tar -c . | docker import - example_archlinux
tar: ./etc/pacman.d/gnupg/S.gpg-agent: socket ignored
tar: ./etc/pacman.d/gnupg/S.gpg-agent.extra: socket ignored
tar: ./etc/pacman.d/gnupg/S.gpg-agent.ssh: socket ignored
tar: ./etc/pacman.d/gnupg/S.scdaemon: socket ignored
tar: ./etc/pacman.d/gnupg/S.gpg-agent.browser: socket ignored
sha256:2b3ed6536389a1184f402ff5a9d20380a3f4aa2c49bdee31df9c7c10186eb889
现在我运行docker映像
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
example_archlinux latest 2b3ed6536389 About a minute ago 881MB
现在我尝试运行图像:
# docker run -ti example_archlinux:latest /bin/bash
[root@3863ba31186b /]#
# docker run -ti example_archlinux:latest ls -al
total 52
drwxr-xr-x 1 root root 4096 Oct 16 08:32 .
drwxr-xr-x 1 root root 4096 Oct 16 08:32 ..
-rwxr-xr-x 1 root root 0 Oct 16 08:32 .dockerenv
lrwxrwxrwx 1 root root 7 Jan 5 2018 bin -> usr/bin
drwxr-xr-x 2 root root 4096 Oct 16 08:01 boot
drwxr-xr-x 5 root root 360 Oct 16 08:32 dev
drwxr-xr-x 1 root root 4096 Oct 16 08:32 etc
drwxr-xr-x 2 root root 4096 Jan 5 2018 home
lrwxrwxrwx 1 root root 7 Jan 5 2018 lib -> usr/lib
lrwxrwxrwx 1 root root 7 Jan 5 2018 lib64 -> usr/lib
drwxr-xr-x 2 root root 4096 Jan 5 2018 mnt
drwxr-xr-x 2 root root 4096 Jan 5 2018 opt
dr-xr-xr-x 275 root root 0 Oct 16 08:32 proc
drwxr-x--- 3 root root 4096 Oct 16 08:01 root
drwxr-xr-x 2 root root 4096 Oct 16 08:01 run
lrwxrwxrwx 1 root root 7 Jan 5 2018 sbin -> usr/bin
drwxr-xr-x 4 root root 4096 Oct 16 08:01 srv
dr-xr-xr-x 13 root root 0 Oct 16 08:32 sys
drwxrwxrwt 2 root root 4096 Oct 16 08:01 tmp
drwxr-xr-x 8 root root 4096 Oct 16 08:10 usr
drwxr-xr-x 12 root root 4096 Oct 16 08:01 var
太好了。它的工作
Q1 : Will docker not ask for login and password of root, assuming i have set root passwd
我想创建我的Django + ngingx + postgresql + redis + git。我将安装并设置所需的软件包。 。 所以我正在测试run命令是否会保存craeted文件夹
# docker run -ti example_archlinux:latest /bin/bash
[root@9f4e56ce38c5 /]# mkdir hare
[root@9f4e56ce38c5 /]# exit
# docker run -ti example_archlinux:latest ls /hare
ls: cannot access '/hare': No such file or directory
我有一个主要问题:
Q2 Since i created a folder and if i exit its not there anymore.
Now what is the best way to use a docker image for my development.
I cant afford that my files are not there after i exit.
So is there any way that the container is permanently created and i can work in it for my development.
OR
在主机或Docker上创建我的源代码的位置。我希望所有东西都集中在一个地方。
答案 0 :(得分:0)
问题1:我从未尝试设置root密码。但是通常,运行容器时,除非使用USER
Dockerfile命令,否则您将以root用户身份登录,这是更安全的方法。进一步了解here
第二季度::每次移除容器时,其中的所有物品都会被销毁。因此,除非将卷绑定到主机,否则您将丢失已创建的文件。卷是标准的处理方式。例如,您可以在docker run
命令中定义一个卷:
docker run -ti -v /host/source/folder:/desired/guest/folder example_archlinux:latest ls -al
现在,您可以从容器或主机添加/删除/更改文件,它将被保留。不会有重复的文件。只是两个人都可以访问它。
更多详细信息here