# Commands

## Clone a docker container

* `docker pull <image>:latest`. The tag `latest` is not required. Clone the container appropriate for your use case, for eg., use `centos` for the latest version of CentOS. CentOS and most other linux operating systems are available as official repositories from the [Docker Hub](https://hub.docker.com).
* To use non-official docker images, you need to add the organisation before the docker image, for example to pull the latest version of `tensorflow`: `docker pull tensorflow/tensorflow:latest`

## Using a docker image

* The docker image can be used directly from the Docker Hub
* To launch the `centos`  docker container, run `docker run -ti tensorflow/tensorflow:latest /bin/bash`

## Running a container with a local volume mounted

* `docker run -ti -v /home/<user>/<mounted-folder>/:/<path-in-container> cbgeo/cb-geo:latest`

## Connecting to a running container

* `docker exec -ti <containerid> /bin/bash`

## Start / stop a container

* `docker start <containerid>`
* `docker stop <containerid>`

## Delete a container

* `docker rm <containerid>`, stop the container before deleting it.&#x20;
* To delete all docker containers `docker rm $(docker ps -a -q)`

## Exposing ports

* To connect to a particular port (for e.g., 3000) in docker container to port `3000` in localhost:

  &#x20; `docker run -ti -p 3000:3000 tensorflow/tensorflow`

## To login as root

* Launching docker as root user: `docker exec -u 0 -ti <containerid> /bin/bash`

## Creating an image from a docker file

* To build an image from docker file run as root `docker build -t "tensorflow/tensorflow" /path/to/Dockerfile`
* `docker history` will show you the effect of each command has on the overall size of the file.

![Docker cheat sheet](https://3073326825-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9PtzjOz4HPAc9i-Kmp%2F-L9Pu2krKYi6YW2a--1m%2F-L9Pu60N2vS-4bHT_Pz_%2Fdocker-cheat-sheet.png?generation=1523017355549590\&alt=media)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kks32-courses.gitbook.io/hpc-containers/docker/commands.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
