Run a Docker image as a container

后端 未结 11 2053
终归单人心
终归单人心 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:09

    You can see your available images using:

    docker images
    

    Then you can run in detached mode so your terminal is still usable. You have several options to run it using a repository name (with or without a tag) or image ID:

    docker run -d repository
    docker run -d repository:tag
    docker run -d image_id
    

    Then you can check your container is running using

    docker ps
    

    docker ps gives you a container ID. You can use it or just the 2/3 first characters to go into your container using:

    docker exec -it container_id /bin/bash
    

    And you can stop it using docker stop container_id and docker rm container_id.

    You can also run your container with -rm arguments so if you stop your container it will automatically be removed.

提交回复
热议问题