Docker Entering the ubuntu Container
We can usedocker runcommand to enter the ubuntu container:
$ sudo docker run -t -i ubuntu:14.04 /bin/bash
ubuntu:14.04 is the image name, parameter description:
- -tIndicates specifying a pseudo-terminal or terminal in the new container
- -iIndicates allowing us to interact with the (STDIN) inside the container.
We also specified a new command inside the container: /bin/bash, which will start the bash shell inside the container.
root@4c484b53a6be:/#
This way, we can operate the container just like we normally operate Ubuntu.
Of course, we can use the exit command or use CTRL-D to exit the container.
$ root@4c484b53a6be:/# exit
If the container already exists, we can use the exec command to enter it:
$ docker start eafd9111ada6 # 启动容器 $ docker exec -it eafd9111ada6 /bin/bash # 进入容器
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 useexitcommand to exit the container, then rundocker commitcommand:
$ exit $ sudo docker commit eafd9111ada6 docker/lua b1829eb2e483c9d353dd8cd21da9bf2f530bd38ccf5a95e08944a887ec856e99
In the command, the ID of the modified container to be committed, the target image repository, and the image name are specified. What commit submits is only the difference between the image that created the container and the container's current state, 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