How do i create an image from a running container?



  • Man page for docker run.
    Man page for docker commit.

    First Step - Create a container.

    $ docker run -d alpine date
    2e09d09c6e9a44e77fc69c4978d571d81e2a85835a48fc1c5894cbb619d9327c
    

    Check the logs for the container.

    $ docker logs 2e09d09c6e9a 
    Wed Jan  9 16:21:21 UTC 2019
    

    Create an image from the running container created in the first step.

    $ docker commit -m "Test in pre-prod" 2e09d09c6e9a alpine_date:latest
    sha256:d2090ef290c7e3888b3fd7936879ee315981f2141691c4ad15df57e0159dccbb
    

    Verify the image was created.

    $ docker images                                                      
    REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
    alpine_date                        latest              d2090ef290c7        3 seconds ago       4.41MB
    my-nginx                           latest              baaf34c109a7        30 hours ago        109MB
    

    Run a container from the image you committed.

    $ docker run -it alpine_date
    Wed Jan  9 16:24:51 UTC 2019
    

    Note: There are automated and more managed ways of creating images, by using Dockerfile and docker build.


Log in to reply
 

© Lightnetics 2024