Docker uses containers to create images.
Category Programming Technology
Entering an Ubuntu Container with Docker
We can use the docker run command to enter an Ubuntu container:
$ sudo docker run -t -i ubuntu:14.04 /bin/bash
ubuntu:14.04 is the image name, parameter explanation:
-t indicates specifying a pseudo-terminal or terminal in the new container.
-i allows us to interact with the container's (STDIN).
We also specified a new command in the container: /bin/bash, which will start the bash shell inside the container.
root@4c484b53a6be:/#
Now we can operate the container just like a regular Ubuntu system.
Of course, we can use the exit command or CTRL-D to exit the container.
$ root@4c484b53a6be:/# exit
If the container already exists, we can use the exec command to enter:
$ docker start eafd9111ada6 # Start the container
$ docker exec -it eafd9111ada6 /bin/bash # Enter the container
Creating an Image with the commit Command
Create a new container command:
$ sudo docker run -i -t ubuntu /bin/bash
Install the Lua language environment:
apt-get update -y && apt-get install -y luajit luarocks
Then exit the container with the exit command, and run the docker commit command:
$ exit
$ sudo docker commit eafd9111ada6 docker/lua
b1829eb2e483c9d353dd8cd21da9bf2f530bd38ccf5a95e08944a887ec856e99
In the command, specify the ID of the modified container to be submitted, the target image repository, and the image name. The commit command only creates the difference between the current state of the container and the image of the container, which is very lightweight.
View the newly created image:
$ sudo docker images docker/lua
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
docker/lua latest b1829eb2e483 25 seconds ago 301.5 MB
** Click to Share Notes
-
-
-