TASK 139: Create a Docker Image From Container
Requirements
One of the Nautilus developer was working to test new changes on a container. He wants to keep a backup of his changes to the container. A new request has been raised for the DevOps team to create a new image from this container. Below are more details about it:
a. Create an image cluster:datacenter on Application Server 3 from a container ubuntu_latest that is running on same server.
Note
The Requirements section stays unchanged. The solution below uses a single docker commit workflow and then verifies the new image tag locally.
Prerequisites
- You can SSH to Application Server 3 and switch to a privileged shell.
- The container ubuntu_latest is already running on the host.
- Docker is installed and you can list containers and images on the server.
Steps
Login to the app server and switch to root. For the server credentials, check out the Project Nautilus documentation.
sshpass -p '**********' ssh -o StrictHostKeyChecking=no banner@172.16.238.12
sudo su -
**********
Check the running container/s and the current image/s.
[root@stapp03 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
76a3fc780671 ubuntu "/bin/bash" About a minute ago Up 59 seconds ubuntu_latest
[root@stapp03 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 99284ca6cea0 3 weeks ago 77.8MB
Create the image from the container.
docker commit ubuntu_latest cluster:datacenter
Verify.
[root@stapp03 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
cluster datacenter d6b5bdb59d86 3 seconds ago 119MB
ubuntu latest 99284ca6cea0 3 weeks ago 77.8MB
Verification
- Confirm the container exists before the commit with
docker ps -a | grep ubuntu_latest. - Confirm the image exists after the commit with
docker images | grep 'cluster\s\+datacenter'. - Verify that the new image tag is cluster:datacenter.