Previous Next        Current Page: NeXtMidas User's Guide / Installing and Using Docker / Docker User Guide / Creating a New Container
back





NeXtMidas Training

Docker Installation


It is currently not possible to create a container without running anything (i.e. commands). To create a new container, you need to use a base image and specify a command to run.

# Usage: sudo docker run [image name] [command to run]
sudo docker run my_img echo "hello"
		

# To name a container instead of having long IDs # Usage: sudo docker run -name [name] [image name] [comm.] sudo docker run -name my_cont_1 my_img echo "hello"


This will output "hello" and you will be right back where you were. (i.e. your host's shell)

As you can not change the command you run after having created a container (hence specifying 
one during "creation"), it is common practice to use process managers and even custom launch
scripts to be able to execute different commands.
		


Running a container:

When you create a container and it stops (either due to its process ending or you stopping it explicitly), you can use “run” to get the container working again with the same command used to create it.

# Usage: sudo docker run [container ID]
sudo docker run c629b7d70666
		


Remember how to find the containers? See above section for listing them.
		


Stopping a container:

To stop a container's process from running:

# Usage: sudo docker stop [container ID]
sudo docker stop c629b7d70666
		


Saving (committing) a container:

If you would like to save the progress and changes you made with a container, you can use “commit” as explained above to save it as an image.

This command turns your container to an image.
		


Remember that with docker, commits are cheap. Do not hesitate to use them to create images to save your progress with a container or to roll back when you need (e.g. like snapshots in time).

Removing / Deleting a container:

Using the ID of a container, you can delete one with rm.

# Usage: sudo docker rm [container ID]
sudo docker rm c629b7d70666
		


back