Docker and Docker Hub Notes - fordsfords/fordsfords.github.io GitHub Wiki
Trying to make a CentOS 5 build environment.
See also Things I forget#Docker_Stuff
Mount a local folder to the container filesystem: Using this mount point as your container working directory, you'll persist locally any files created within the container and you'll make the container aware of any local changes made to project files.
The following was done on my personal Mac after installing Docker Desktop and running it. For clarity, I will include the prompts so that you know what is running at each point.
Create a directory "bld5" and "cd" to it. Then:
bld5 $ docker run --rm -i -t --name bld5 astj/centos5-vault /bin/bash
The terminal window is now running in the container's environment.
[root@b5c7b30415b9 /]# ls bin dev etc home lib lib64 lost+found media mnt opt proc root sbin selinux srv sys tmp usr var [root@b5c7b30415b9 home]# gcc bash: gcc: command not found [root@b5c7b30415b9 home]# yum search gcc ... gcc.x86_64 : Various compilers (C, C++, Objective-C, Java, ...) ... [root@b5c7b30415b9 home]# yum install gcc.x86_64 ... [root@b5c7b30415b9 home]# ldd --version ldd (GNU libc) 2.5
In a separate host window:
~ $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b5c7b30415b9 astj/centos5-vault "/bin/bash" 14 minutes ago Up 14 minutes bld5 ~ $ docker commit b5c7b30415b9
In the container window:
exit [root@b5c7b30415b9 home]# exit exit bld5 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bld5 $ docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bld5 $ docker images -a REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> 582a5542f263 10 minutes ago 477MB astj/centos5-vault latest e79faab040e1 2 years ago 284MB
Run it again:
bld5 $ docker run --rm -i -t --name bld5 582a5542f263 /bin/bash [root@3d4149bdc8e9 /]# gcc gcc: no input files [root@3d4149bdc8e9 /]# exit exit
Save it (see difference between export and save):
$ docker save 582a5542f263 | gzip -c >bld5v2.tz # will take about 1 minute $ ls -lh bld5v2.tz -rw-r--r-- 1 sford_itunes staff 136M Jan 26 08:19 bld5v2.tz
Good luck. I couldn't get it to work, but apparently others could.
- Install CentOS 7 "everything"
- Select "minimal install" and add "development tools"
- Do *not* do the "yum update".
sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine sudo yum install -y yum-utils device-mapper-persistent-data lvm2 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo yum install -y docker-ce docker-ce-cli containerd.io sudo systemctl start docker sudo systemctl enable docker sudo docker run --rm hello-world gunzip -c <bld5v2.tz | sudo docker load sudo docker images -a sudo docker run --rm -i -t --name bld5 (image ID) /bin/bash
Also, apparently the Fedora team upgraded to something called "CgroupsV2", which broke docker. According to reddit, you need to do the following:
sudo vi /etc/default/grubAdd systemd.unified_cgroup_hierarchy=0 to the GRUB_CMDLINE_LINUX. Mine ended up like this:
GRUB_CMDLINE_LINUX="resume=/dev/mapper/fedora_localhost--live-swap rd.lvm.lv=fedora_localhost-live/root rd.lvm.lv=fedora_localhost-live/swap systemd.unified_cgroup_hierarchy=0 rhgb quiet"Write and quit. Then:
sudo grub2-mkconfig sudo reboot now
Then:
sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine sudo yum install -y yum-utils device-mapper-persistent-data lvm2 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo yum install docker-ce docker-ce-cli containerd.io sudo systemctl start docker sudo systemctl enable docker sudo docker run --rm hello-world gunzip -c <bld5v2.tz | sudo docker load sudo docker run --rm -i -t --name bld5 fordsfords/bld5:v2 /bin/bash
Images:
- docker images -a # list all stored images
- docker save blah_img | gzip -c >blah_img.tz # save image
- gunzip -c <blah_img.tz | docker load # load image
- docker image rm blah_img # delete stored image
- docker ps -a # list containers
- docker stop blah_cont # stop container.
- docker rm blah_cont # remove container.
-
docker run --rm -i -t --name blah_cont --hostname blah_host blah_img /bin/bash
- --rm : Automatically remove the container when it exits
- -i : (--interactive) Keep STDIN open even if not attached
- -t : (--tty) Allocate a pseudo-TTY
- --name blah_cont : Assign a name to the container
- --hostname blah_host : Container host name
- blah_img : Image
- /bin/bash : Command to run
- docker cp blah_cont:/home/blah/deliverables.tz /tmp/deliverables.tz
- docker commit blah_cont blah_img2 # create new image from modified container
- Dockerfile reference
- https://docker-curriculum.com/ - docker tutorial.
- https://auth0.com/blog/use-docker-to-create-a-node-development-environment/
- Google for:
docker "base image" "from scratch" centos
- https://github.com/moby/moby/blob/master/contrib/mkimage-yum.sh - create a CentOS base image from scratch, using a Centos system.