Run a Docker image as a container

后端 未结 11 2041
终归单人心
终归单人心 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 05:06

    Get the name or id of the image you would like to run, with this command:

    docker images
    

    The Docker run command is used in the following way:

    docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
    

    Below I have included the dispatch, name, publish, volume and restart options before specifying the image name or id:

    docker run -d --name  container-name -p localhost:80:80 -v $HOME/myContainer/configDir:/myImage/configDir --restart=always image-name
    

    Where:

    --detach , -d        Run container in background and print container ID
    --name                Assign a name to the container
    --publish , -p        Publish a container’s port(s) to the host
    --volume , -v        Bind mount a volume
    --restart            Restart policy to apply when a container exits
    

    For more information, please check out the official Docker run reference.

提交回复
热议问题