Skip to content
Marcel edited this page Aug 31, 2015 · 4 revisions

Docker HOW-TO's

Other sources of information

Working with images

Running a command in interactive mode on a container

$ docker run -it --rm [image] [program]

Note: The command starts a container based on [image] and runs [program] in interactive mode (-it). When the container is stopped, all the state will be removed (--rm).

Downloading an image

$ docker pull [image]

Uploading an image

$ docker push [image]

Building a new image from a Dockerfile

$ docker build -t image-name .

Note: . indicates that the Dockerfile is in the current directory.

Listing all images

$ docker images

Removing an image

$ docker rmi [image ID or name]

Note: When an image is removed, all related containers are removed as well.

Removing all dangling images (aka cleaning up)

$ docker rmi $(docker images --quiet --filter "dangling=true")

Extending images

Create a Dockerfile extending an existing image and add some layers to it by copying files (using the ADD command), executing commands (using the CMD command), etc. Dockerfile:

FROM jboss/wildfly
ADD standalone-custom.xml /opt/wildfly/standalone/configuration/
CMD ["/opt/wildfly/bin/standalone.sh", "-c", "standalone-custom.xml", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]

Working with containers

Listing containers

$ docker ps

Note: docker ps -a lists all containers that have been exited as well.

Inspecting a container

$ docker inspect [container name or id]

Note: Retrieve a container name or id by running docker ps.

Killing a container

$ docker kill [container name or id]

Note: Retrieve a container name or id by running docker ps.

Removing a container

$ docker rm [container name or id]

Finding a container IP address

$ docker ps
$ docker inspect [container name or ID]

Note: Look for IPAddress on the container JSON data.

Port forwarding

$ docker run -it --rm -p 8080:8080 jboss/wildfly

Note: You may add as many -p parameters as needed.

Running a program on in an existing container

$ docker exec -i -t [container name or ID] [program]

Using Dockerfiles

See Dockerfile Best Practices.

Using the jboss/wildfly image

Forwarding the default HTTP and administration ports

$ docker run -it --rm -p 8080:8080 -p 9990:9990 jboss/wildfly

Deploying an app using the Deployment scanner

Dockerfile:

FROM jboss/wildfly
ADD application.war /opt/jboss/wildfly/standalone/deployments/