After installing Docker on CentOS or Fedora, you need to add yourself to docker group to be able to run Docker as a non-root user. Use this command for that:
$ sudo usermod -a -G docker $USER
Log out, and log back in to activate the group change.
At this point, you should be able to run docker command as a unprivileged user.
Basic Usage of Docker
To start a new Docker container, you need to decide which Docker image to use for the container. You can search the official Docker image index which lists publicly available Docker images. The Docker index includes Linux base images managed by Docker team (e.g., Ubuntu, Debian, Fedora, CentOS), as well as user-contributed custom images (e.g.,MySQL, Redis, WordPress).
For example, to start a Ubuntu container in the interactive mode, run the following command. The last argument '/bin/bash' is to be executed inside a container upon its launch.
$ docker run -i -t ubuntu /bin/bash
The first time you run the above command, it will download available Ubuntu docker image(s) over networks, and then boot up a Docker container using the image. A Ubuntu container will boot up instantly, and you will see a console prompt inside the container. You can access a full-fledged Ubuntu operating system inside the container sandbox.
If you type 'exit' at the prompt, you will get out of the container, and it will be stopped.
To get a list of all containers (including stopped ones), run:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6a08a0b2bb4c ubuntu:14.04 /bin/bash About a minute ago Exit 0 cocky_ritchie
To re-start a stopped container in daemon mode:
$ docker start [container-id]
To remove a stopped container:
$ docker rm [container-id]
To attach to a background-running container in order to view or interact with the container:
$ docker attach [container-id]
You can freely customize a running container (e.g., installing new software). If you want to save the changes in the current container, first get out of the container's interactive mode by typing "exit" at the prompt. Then save the changed image as a different image by using this command:
$ docker commit [container-id] [new-image-name]
To get the container ID of your container, you can use "docker ps -a" command as described earlier.
Once you have created a new image like this, you can launch a new container off of this image.
You can also download any public container images (e.g., ubuntu, bowery/mysql) and store them in a local repository as follows.
$ docker pull [image name]
To view all locally downloaded/saved container images:
$ docker images
You can choose a specific image to boot a container from:
$ docker run -i -t [image-id] /bin/bash
To remove a container image from the local repository: