install docker rhel
Add the official docker repo for docker-ce to yum repos.
sudo curl https://download.docker.com/linux/centos/docker-ce.repo > /home/xxx/docker-ce.repo --proxy http://172.30.230.45:8080
sudo mv /home/xxx/docker-ce.repo /etc/yum.repos.d/docker-ce.repo #move the repo to yum.repos.d
Import GPG key
sudo curl https://download.docker.com/linux/centos/gpg > /home/xxx/docker-key --proxy http://xxx.xxx.xx.x:8080
sudo rpm --import /home/xxx/docker-key
update the yum repos
sudo yum update
install docker-ce
sudo yum install docker-ce
The installation should have added docker to systemd service and enabled it. A systemd service definition is created in
/usr/lib/systemd/system/docker.service
Check the run status:
sudo systemctl status docker
if not, restart or run
sudo systemctl enable docker
and then restart
Docker can download images from Docker Hub, but it may need proxy setting first.
The Docker daemon use the HTTP_PROXY, HTTPS_PROXY environmental variables in its start-up environment.
Firstly create a folder for the docker systemd service.
sudo mkdir /etc/systemd/system/docker.service.d
Within the folder, create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable
[Service]
Environment="HTTP_PROXY=http://xxx.xxx.xx.xx:8080"
If you are behind an https proxy than create a https-proxy.conf file and hava
[Service]
Environment="HTTPS_PROXY=http://xxx.xxx.xx.xx:8080"
Restart docker to take effect.
sudo systemctl restart docker
check if the http proxy is in use.
sudo systemctl show --property=Environment docker
Search for a docker image on Docker Hub
sudo docker search hello-world
login to docker hub. this is required before pulling images from docker hub.
sudo docker login
Type in the login id (not meial) and password. Need to sign up on docker hub first to have an account.
If the firewall or proxy blocks docker, this wont work.
Now pull the hello-world image from docker hub
sudo docker pull hello-world
Test run hello world
sudo docker run hello-world
Test run Ubuntu. If running an Ubuntu from docker, you may enter the terminal of the Ubuntu instance. The -i means interative, the -t means tty (teletype) which is known as terminal.
docker run -it ubuntu
Once you start running an image, it becomes a container instance and you may start adding / removing stuff within it.
A few container commands:
sudo docker ps #view active containers
sudo docker ps -a #view all containers, active or inactive
sudo docker rm containerid #remove an container with the id/name
As you container instance grows, you may want to save it as a separate image, so you start off the new image. the repository is usually your docker hub user name.
sudo docker commit -m "message, what you did to the image" -a "author" container_id repository/new_image_name
sudo docker images #shows all the images currently available locally including the ones you created and pulled from hub.