AWS - Day 3 - Create Container from another container

John Rankin @ August 20, 2018

There are Two ways to create your own container.  

One way is to use an existing docker container,  make your changes to it, and then save it as your new container.  The other way is to create one from scratch using a Dockerfile.   

For this lesson, we are going to go ahead and start with the first one, by modifying an existing container.

This Tutorial will teach the following:

  1. How to log into your Running Container via Interactive Shell.
    1. Install an Application  ---  (we are installing vim  so we can easily edit files)
  2. Copy files from HOST to Container
  3. Save, and Tag off your modified container to a repo.


From the "Intro To Docker Post" i've done earlier.. lets re-startup an nginx container and map port 80 to 8080 so I can see stuff :)

docker run -p 8080:80 -d nginx

Once that's started up lets run docker ps  and retrieve the "NAMES" item associated with the container.  This is the "hostname" of the container that we will be using to be able to log in, or transfer files to the running container.   In this case, our hostname for the nginx container will be confident_bardeen ... This hostname will change everytime you start a container.

root@damrkul2:~# docker ps
3344f3e0bd26 nginx "nginx -g 'daemon of…" About a minute ago Up About a minute>80/tcp confident_bardeen

Log into the container via Interactive Shell

The format for logging in via Interactive Shell will be the following: 

  • docker exec -it {{CONTAINER_NAME}} /bin/bash"

So lets log into ours 

root@damrkul2:~# docker exec -it confident_bardeen /bin/bash

That was easy enough... now it seems alot of containers may not have vim installed.   So lets install the vim software so we can look and edit files inside the container.     

More and likely you will need to update youre repostory from inside the container... Lets  run an apt-get update and install vim .

root@3344f3e0bd26:/# apt-get update;
.......  (removed bunch of lines, but it installed)
Reading package lists... Done

root@3344f3e0bd26:/# apt-get install vim -y
.......  (removed bunch of lines, but it installed)
Setting up vim (2:8.0.0197-4+deb9u1) ...

root@3344f3e0bd26:/# which vim

Congrats! you've installed your first peice of SW onto a running container... I

Lets now copy a file into the container that can be distributed with our docker image.  We will be copying a new index.html to the container.  

From our HOST machine lets use the docker cp command.

root@damrkul2:~# docker cp /var/www/dockertest/index.html confident_bardeen:/usr/share/nginx/html

Lets go check to see if the changes happend.

Awesome .   We've installed a peice of software, and we have also transferred something to the container.   I also wanted to know we can use the same docker cp to send files from the CONTAINER to the HOST, by swapping the arguments.


Alright... so now lets save off this image.

Lets log into DockerHub

root@damrkul2:~# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to to create one.
Username: rekous
Login Succeeded


Lets Commit our Image:

root@damrkul2:~# docker commit -m "MyFirst Save" -a "Rekous" confident_bardeen rekous/firstsave:v1

Lets Push our Image:

root@damrkul2:~# docker push rekous/firstsave:v1
The push refers to repository []
73ac60fbddde: Pushed
08d25fa0442e: Mounted from library/nginx
a8c4aeeaa045: Mounted from library/nginx
cdb3f9544e4c: Mounted from library/nginx
v1: digest: sha256:fb1998df3ca47e7c9e4a5b55f3e392291dd8e990ebb3994ea710c01e1ca426fe size: 1160

Lets stop our "confident_bardeen" container...   and tryout our new one..

root@damrkul2:~# docker run -p 8080:80 -d rekous/firstsave:v1


 And there ya have it!!!  I think this is good enough to get me started!



Most Recent Posts

Blog Test

Read This
October 16, 2018

Day 7 - DynamoDB - and Working with 2 Services - Lambda

Read This
August 25, 2018

Day 6 - Lambda - Creating an API

Read This
August 23, 2018

AWS - Day 5 - S3 - Simple Storage Service

Read This
August 22, 2018

AWS - Day 4 - AWS CLI Useful Scripts

Read This
August 21, 2018

AWS - Day 3 - Create Container from another container

Read This
August 20, 2018

Day 2 - Docker Intro

Read This
August 17, 2018

AWS - Day1 - Tutorial - Launching my first Docker Container

Read This
August 16, 2018

AWS - Day 1 - Signing up and testing out their tutorials

Read This
August 16, 2018

Dynamic Programming - Edit Distance

Read This
December 19, 2016

Dynamic Programming - Fibonacci

Read This
December 19, 2016

What I Do

Read This
June 23, 2015

First Blog Post

Read This
June 23, 2015