Use docker images to see what images you have locally on your host.
$ sudo docker images
Use docker search to see what images are available on Docker Hub.
$ sudo docker search fedora
Use docker run
to run an application inside a container.
The following command pulls Fedora image, creates a container from it and runs Bash shell inside it.
$ sudo docker run -it fedora bash
Other useful options to use with run
are for example -d
to run a container in background (to daemonize it) or --name
to give container a name which you can later use with docker stop/start
.
See also Docker run reference.
Other useful commands regarding running containers are for example:
docker exec -it [container-id] bash
If you change anything (like install new packages in the above example with Bash) in the running container and exit the container the changes are not automatically saved into the Fedora image. If you want to save them in an image, use docker commit.
Another option how to create an image is by building it from Dockerfile, see below.
There are already existing Dockerfiles in Fedora-Dockerfiles repository. You can use them as examples for creating your own Dockerfile. Each directory contains a Dockerfile and a README with instructions how to build the image and run a container from it.
A Dockerfile content can be as simple as:
FROM fedora:latest
CMD env
For description of instructions used in Dockerfile see Dockerfile reference and Best practices for writing Dockerfiles
In a directory with a Dockerfile run
$ sudo docker build -t "my-image" .
If the build is successful you can see the my-image
image in docker images
output.
See also Build your own image and Building an image from a Dockerfile for more thorough description.
Authors: Adam Samalik, Budh Ram Gurung, Jarek Prokop, Jiri Popelka, Nick Dirschel