Run a Docker image as a container

后端 未结 11 2052
终归单人心
终归单人心 2020-12-04 04:27

After building a Docker image from a dockerfile, I see the image was built successfully, but what do I do with it? Shouldn\'t i be able to run it as a container

11条回答
  •  一向
    一向 (楼主)
    2020-12-04 04:55

    Since you have created an image from the Dockerfile, the image currently is not in active state. In order to work you need to run this image inside a container.

    The $ docker images command describes how many images are currently available in the local repository. and

    docker ps -a
    

    shows how many containers are currently available, i.e. the list of active and exited containers.

    There are two ways to run the image in the container:

    $ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
    

    In detached mode:

    -d=false: Detached mode: Run container in the background, print new container id
    

    In interactive mode:

    -i :Keep STDIN open even if not attached
    

    Here is the Docker run command

    $ docker run image_name:tag_name
    

    For more clarification on Docker run, you can visit Docker run reference.

    It's the best material to understand Docker.

提交回复
热议问题