1

I am an new bee to Docker and i am trying to create/use the existing image to bring up my application. After reading couple of stackoverflow posts and Docker documentations I was able bring up my application using Docker containers. Now I am looking for correct way to saving the modified Docker container, So that I can reuse the container to bring up my application by running docker command.

I see people use $docker commit to save the docker container. If i run this command, where does the container gets saved ? will anybody else able to download my saved container ?

I am planning to deploy the saved docker container to the AWS cloud as well.

Any suggestions or comments on this would be helpful.

Update to the post Here is my dockerfile which i use to download and build the container

FROM tomcat:7.0.82-jre8
RUN apt-get update && apt-get -y upgrade
WORKDIR /usr/local/tomcat
COPY /app.war /usr/local/tomcat/webapps/app.war
RUN unzip /usr/local/tomcat/webapps/app.war -d /usr/local/tomcat/webapps/app
RUN apt-get update && apt-get install -y dos2unix
EXPOSE 8080
COPY tomcat-users.xml /usr/local/tomcat/conf/
COPY config1.xml /usr/local/tomcat/webapps/app/conf/
COPY config2.properties /usr/local/tomcat/webapps/app/conf/properties/
COPY config4.properties /usr/local/tomcat/webapps/app/conf/

ENV JAVA_OPTS="-Xms2G -Xmx2G"
# Copy Entrypoint script in the container
COPY ./docker-entrypoint.sh / 
RUN dos2unix /docker-entrypoint.sh && apt-get --purge remove -y dos2unix && rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["/docker-entrypoint.sh"]
babs84
  • 421
  • 1
  • 10
  • 18

2 Answers2

2

If i run this command, where does the container gets saved ?

On your local machine. Just type docker images and you will see it.

will anybody else able to download my saved container ?

No, because it's only on your local machine.


But this is NOT the way how you should use docker! Don't modify the running container! Instead, write a Dockerfile and build your image via this Dockerfile.

Munchkin
  • 4,528
  • 7
  • 45
  • 93
  • ok. How do i ship this image to a different desktop machine ? for example i have updated a container which actually downloads a image from the official tomcat repository and i saved the container in my local machine using the $docker commit command. After that I want to ship this container to a different box or a desktop machine which is in the same network ? How can i do that ? – babs84 Oct 24 '17 at 18:42
  • 1
    Best way is to use a Docker repository like Docker Hub: Do `docker push` on your local machine and `docker pull` on the remote. An (ugly) alternative is to export your image into a .tar file (`docker export`), copy this tar to your remote machine and import this tar (`docker import`). – Munchkin Oct 24 '17 at 18:46
  • I know that Docker Hub is where you download all the existing containers. If i do the $docker push, it will be available in the Docker Hub. Does that mean that anyone can access my container ? . But i like the other way of exporting my image to a tar file and i can use the same in a different box as well. Between can i know why it is ugly ? – babs84 Oct 24 '17 at 18:52
  • I have updated my original post with the dockerfile which i use to build the container – babs84 Oct 24 '17 at 18:58
  • 1
    You can create private repos on Docker Hub which are only accessible for authorized users. // See this post for some hints on creating smaller Docker images: https://stackoverflow.com/questions/24394243/why-are-docker-container-images-so-large/39078793 – Munchkin Oct 24 '17 at 19:22
0

From the Docker Documentation

Generally, it is better to use Dockerfiles to manage your images in a documented and maintainable way.

...

The commit operation will not include any data contained in volumes mounted inside the container.

Commit a container:

$ docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS              NAMES
c3f279d17e0a        ubuntu:12.04        /bin/bash           7 days ago          Up 25 hours                            desperate_dubinsky
197387f1b436        ubuntu:12.04        /bin/bash           7 days ago          Up 25 hours                            focused_hamilton

$ docker commit c3f279d17e0a  svendowideit/testimage:version3

f5283438590d

$ docker images

REPOSITORY                        TAG                 ID                  CREATED             SIZE
svendowideit/testimage            version3            f5283438590d        16 seconds ago      335.7 MB

As you can see in the example the image saved is stored in the machine which runs the docker commit

juanlumn
  • 6,155
  • 2
  • 30
  • 39