From the state where Docker is not installed, install Docker and try using the zypper command with openSUSE on the container. Combines LPIC and Docker learning.
macOS Catalina (version 10.15.7) MacBook Pro Docker version 19.03.13
Follow the instructions in Docker Official and install from Docker Hub ..
Since there was a tutorial after installation, enter the command as instructed on Docker Desktop (you can also click the button).
As for the content,
① Build a container named repo
from the image ʻalpine / git, and create a clone from the GitHub repository on the container. (2) Copy the files in the container locally. ③ Build an image from the Dockerfile and name it
docker101tutorial. ④ Name the created image
docker / docker101tutorial`, upload it to Docker Hub and share it.
$ docker run --name repo alpine/git clone https://github.com/docker/getting-started.git
$ docker cp repo:/git/getting-started/ .
$ cd getting-started/
$ docker build -t docker101tutorial .
$ docker tag docker101tutorial dockeridok/docker101tutorial
$ docker push dockeridok/docker101tutorial
Commands, etc. | Explanation |
---|---|
docker run [option]image[:Tag or@Digest value] [command] [argument...] | Create a container layer on the specified image and start it. Performs the same operation as docker create → docker start. If the specified image does not exist locally, it will be downloaded from Docker Hub, so it may be accompanied by docker pull operation. This time the specified image alpine/I don't have git locally, so I'm downloading it from Docker Hub. |
--name | Give the container a name. This time I named it repo. The default is to name it from a random string. |
clone | I'm cloning from GitHub. Since git is specified in ENTRYPOINT, git clone is actually executed. |
cp container: path local path | Copy the contents of the container's file system to your local path. |
docker build [option]Path or URL or- | Build a new image from the Dockerfile in the path. |
-t | Name: tag Specify the name and optional tags in the format. This time, only the name is specified and the tag is omitted. |
docker tag [option]image[:tag] [Registry host/][User name/]name[:tag] | リポジトリ内のイメージにtag付。今回はdocker101tutorial To the imagedockeridok/docker101tutorial というnameをつけている。 |
docker push [option]name[:tag] | You can share the image in the Docker Hub registry or in your own registry. |
Dockerfile
The Dockerfile on which the image is based. Docker reads instructions from Dockerfile and automatically builds an image. This time, we will deepen our understanding of Docker by using the simple Dockerfile from the official website tutorial as a sample.
Dockerfile
#Base image
FROM node:current-slim
#RUN specified in Dockerfile,Specify the working directory when executing instructions such as COPY
WORKDIR /usr/src/app
#Copy the file from the host into the container.
COPY package.json .
#Execute the command in the image file system.
RUN npm install
#Release the container port.
EXPOSE 8080
#Execute the command specified in the container. CMD provides defaults when running containers.
CMD [ "npm", "start" ]
#Copy all files etc. into the container.
COPY . .
#Delete container
docker rm container name
#Delete the running container.--force stops the container.
docker rm --force container name
#Container confirmation
docker ps -a
#Image deletion
docker rmi image name
#Delete all images.-The q option displays only the ID.
docker rmi `docker images -q`
#Image confirmation
docker images
#Start the container. From the tutorial on the official website. Details of the command will be described later.
docker run --publish 8000:8080 --detach --name bb bulletinboard:1.0
#Create an image from a container
docker commit -m "message" -a ”person in charge" \
Container ID hogeuser/opensuse:v2
Commands, etc. | Explanation |
---|---|
--publish 8000:8080 | Publish the container port to the host side. Forward host port 8000 to container port 8080. |
--detach | Run the container in the background. |
docker commit [option]container[Repository[:tag]] | Create a new image that reflects the container's file changes and settings. |
Now that I have some idea of Docker, I'll create an openSUSE container for the subject.
The name of the openSUSE image was found by DockerHub opensuse / leap, so all you have to do is run it. If you just check the command, it is faster than building a virtual machine.
% docker run -it opensuse/leap:latest
Unable to find image 'opensuse/leap:latest' locally
latest: Pulling from opensuse/leap
658f48177d00: Already exists
Digest: sha256:
Status: Downloaded newer image for opensuse/leap:latest
0a5ec012802e:/ # cat /etc/*release
NAME="openSUSE Leap"
VERSION="15.2"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
VERSION_ID="15.2"
PRETTY_NAME="openSUSE Leap 15.2"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:leap:15.2"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"
0a5ec012802e:/ # zypper --version
zypper 1.14.38
Commands, etc. | Explanation |
---|---|
-i | Get the standard input (STDIN) of the container. Standard input will be possible in the container. |
-t | Assign a pseudo terminal inside the container.-By combining with t, you can enter commands like a normal terminal (although I don't know how much you can do as usual). |
I also built and used a CentOS container, but it was annoying to see can't set the locale; make sure $ LC_ * and $ LANG are correct
, so when I tried to change the locale,
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to create bus connection: Host is down
Is displayed. Can't systemd work because the shell is using PID1?
[root@15900d9cd863 /]bash# ps
PID TTY TIME CMD
1 pts/0 00:00:00 bash
162 pts/0 00:00:00 ps
I solved it by following this article. Hyakuzo's room "When systemctl cannot be used with CentOS7 container"
docker run -itd --privileged image/sbin/init
docker exec -it container/bin/bash
[root@d7a7f918cfde /]bash# ps
PID TTY TIME CMD
119 pts/1 00:00:00 bash
15560 pts/1 00:00:00 ps
Commands, etc. | Explanation |
---|---|
--privileged | Give extended privileges (all privileges) to the container. You can connect to other containers and connect to all devices on the host. |
/sbin/init | With a symbolic link to systemd--By using with privileged/sbin/init will work and systemctl etc. can be executed |
docker exec [option]Container command[argument...] | Execute the command in the running container. This time, when you execute the command in the container, "/bin/It means "bash command"? |
By the way, locale setting. After setting, it should be reflected in source /etc/locale.conf
(the above command is not executed because it came out of the container by reboot
).
[root@d7a7f918cfde /]bash# localectl
System Locale: LANG=en_US.UTF-8
VC Keymap: us
X11 Layout: n/a
[root@d7a7f918cfde /]bash# localectl list-locales
C.utf8
[root@d7a7f918cfde /]bash# dnf -y install langpacks-ja
[root@d7a7f918cfde /]bash# localectl list-locales
C.utf8
ja_JP.eucjp
ja_JP.utf8
[root@d7a7f918cfde /]bash# localectl set-locale LANG=ja_JP.utf8
[root@d7a7f918cfde /]bash# localectl
System Locale: LANG=ja_JP.utf8
VC Keymap: us
X11 Layout: n/a
I want to make the prompt part easy to understand, so I will color it. Reference site: Tohoho's WWW "Introduction to Shell".
#Shell confirmation
$ echo $SHELL
#Edit configuration file. Color it green to show the time.
$ vi /etc/bashrc
export PS1="\[\e[1;32m\][\u@\h \w][\t]\[\e[0m\]\s\ $"
#Reflect
$ source /etc/bashrc
When I displayed the time at the prompt, it was not Japan, so change it to Japan.
[root@f95fa15cf5fb /][13:26:29]bash#timedatectl
Local time:Day 2020-11-01 13:26:37 UTC
Universal time:Day 2020-11-01 13:26:37 UTC
RTC time:Day 2020-11-01 13:26:37
Time zone: UTC (UTC, +0000)
System clock synchronized: no
NTP service: n/a
RTC in local TZ: no
[root@f95fa15cf5fb /][13:26:37]bash#timedatectl set-timezone Asia/Tokyo
[root@f95fa15cf5fb /][22:27:03]bash#timedatectl
Local time:Day 2020-11-01 22:27:07 JST
Universal time:Day 2020-11-01 13:27:07 UTC
RTC time:Day 2020-11-01 13:27:07
Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: no
NTP service: n/a
RTC in local TZ: no
It was troublesome because the completion function was often not enabled, so enable it. It's not pretty, but after executing the following command, I got out of the container, committed the container to create an image, and made the image a container to enable the completion function.
[root@f95fa15cf5fb /][22:32:18]bash#yum info bash-completion
Last metadata expiration check: 1:18:08 ago on November 01, 2020 21:24:15.
Available Packages
Name : bash-completion
Epoch : 1
Version : 2.7
Release : 5.el8
Architecture : noarch
Size : 274 k
Source : bash-completion-2.7-5.el8.src.rpm
Repository : BaseOS
Summary : Programmable completion for Bash
URL : https://github.com/scop/bash-completion
License : GPLv2+
Description : bash-completion is a collection of shell functions that take advantage
: of the programmable completion feature of bash.
[root@f95fa15cf5fb /][22:42:23]bash#yum install bash-completion
Recommended Posts