Docker useful commands

This intends to be a list of easy to find useful commands for working with docker. If you are looking for information about docker go to  Docker docs homepage

To remove all the containers:

$ docker rm $(docker ps -aq)

To open a shell in a new container sharing a folder:

$ docker run -t -i -v /my/own/dir:/opt/ myImageName

To open a shell in a running container:

$ docker exec -t -i myContainerName  /bin/bash

See container IP address:

$ docker inspect  myContainerName | grep IPAddress

Launch an image in background:

$docker run -d myImageName

To assign a private IP to a docker container:

$ docker network create --subnet=10.0.0.0/16 myDockerNet
$ docker run --net myDockerNet --ip 10.0.0.2 -d myImageName

To copy a file to a container:

docker cp localfile  myContainerName:remotefile

To copy a file from a container:

docker cp  myContainerName:remotefile localfile
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s