Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagebash
themeMidnight
titleGetting a shell in a running container
collapsetrue
docker exec -it <container name> bash

 

This returns a shell that gives you terminal level access to your container. It might be highly useful when setting up things in a container that was not already fixed by the docker script, or for just getting more familiar with the environment you’ve created. Note the –it switches used; they make the session interactive, which means that stdin from your current shell will be hooked up to the shell granted by the container. 

 

 

 

Code Block
languagebash
themeMidnight
titleMoving files in and out of a container
collapsetrue
docker cp <container_name> path/to/src/file path/to/dest/file

This command allows copying single files to or from a container. Usage-wise it is more or less identical to the normal cp command.

 

 

Code Block
languagebash
themeMidnight
titleMounting external directories
collapsetrue
docker run -v /host/path/to/dir:/container/mount/location --name <container...

If you want to keep whole directories of files synched or a permanent place to store output, then the copy command is not going to cut it. Fortunately, docker comes with the option to mount whole directories from the host machine into the container. You can do this by adding an extra argument to the docker run command, specifying the source directory root and the location you want it to show up in the container. While it is often convenient to mount your own home directory, this is in my experience currently not feasible on most docker setups we got because the ticket used to access your home folder is not transferred to the docker program. One alternative is to use the host machine’s /tmp folder, but this is naturally a bad idea if you're looking for permanent storage. Therefore, most machines are set up with a /data folder, where users of the system can get their own subfolder which they can mount into the containers they spawn.

 

 

 

Security issues 

 

On most NTNU systems docker runs as root, meaning that anything you do through docker will be run as root – not just in your container but also when interacting with the host machine. Please keep this in mind when working and be responsible / careful.





 

 

Info

Feel free to help us provide a better wiki by sharing your skills and knowledge.

...