I will introduce the basic options that can be specified during Docker run.
It is important to avoid putting files on the container side as much as possible so that the container is not too large. At such times, use the -v option, which allows you to mount the host's files in a container. The way to write is as follows.
-v <host>:<container>
docker run -it -v ~/Desktop/to_container:/host_folder <image> bash
Sharing the file system allows the container to access the host's file system. Unless otherwise specified, the container will be running as root. It is not good to access the host side as it is, so you need to set the access authority. If you execute the container by specifying your own user id and user group and specifying the execution user, you can create a container so that users other than root privileges can operate inside the container.
-u 501:20
However, it is troublesome to check the user id and user group each time and execute the command, so it is convenient to describe so that the user id and group can be executed and run.
-u $(id -u):$(id -g)
If you put a linux command in $ (), the command will be executed using the execution result. When you actually run and run bash, you should see the user as shown below.
I have no name!@<serial>
The cause is that there is no user such as 501 on the container, so if you create a user appropriately, it will be displayed with the correct user name.
When setting up multiple containers, access is not possible unless the host port and container port are linked. The description method is not much different from the one introduced so far, and is as follows.
-p <host port>: <container port>
If you do not set the host CPU and memory so that they are not used up, resources may be exhausted. There is an option to set an upper limit to prevent this from happening.
-cpus <number of cores> --memory <memory capacity byte>
ex. Set the upper limit of 2 cores and 4G memory and start the container.
docker run --cpus 2 --memory 4g <image> bash
You can check the id of the container, the time it was created, the environment variables, the CPU allocated, and the memory. The command is below.
docker inspect <container ID>
To the above command| grep -i cpu
、| grep -i memory
Please connect and check the settings.
This time is over.