If you have not yet built a Docker Image, or don't have Docker installed on your host system, please see Part 1 of this Tutorial Series: Get Started with Docker Today.
Create a Docker Hub Account and Personal Access Tokens
Sign up for a free Docker Hub account here: https://hub.docker.com/signup
Create a Repository, either Public or Private.
- NOTE: You get 1 free Private repository.
From your Account Settings, go to Security. Here you can create a personal access token.
Click New Access Token and give it a name or description.
- You can create as many tokens as you wish.
- You can revoke access at any time by disabling or permanently deleting a token.
Once you've created a token, record it in a secure location, such as in a password vault. The token will be displayed only one time. You will not be able to access it again from anywhere in your Docker Hub account.
Now you can use your token to log into your Docker Hub account from a Linux machine. Do as follows:
$ sudo docker login --username <username>
- When you’re prompted for a password, enter your token.
Next we will push an image built on a local host machine to our Docker Hub account.
Push an Image to Your Docker Hub Account
If you have not already done so, build your Docker image. For example:
- Move into your project directory:
$ cd new_app/
- Build the image:
$ sudo docker build --tag=hello-python3 .
- Make sure the image runs:
$ sudo docker run -p 80:80 hello-python3
tag your image according to the name of the Repository you created in your Docker Hub account:
$ sudo docker tag hello-python3 kernelmastery/hello-python3
push your tagged image to your Repository:
$ sudo docker push kernelmastery/hello-python3
That's the workflow.
Pull and Test the Image from Another Machine
Next we will
pull the image and
run it from another host machine. We will call it the 'Test System'.
Regarding the use of Login Tokens on multiple systems:
- If you wish, you can create a separate access token for the Test System. Or use the same token. It is up to you.
- Generally, it is advisable to use separate tokens on each host, however. Then you can revoke access for one host at a time.
- For now, we don't even need to log into the Docker Hub account if you chose to create a Public Repository. If yours is Private, use or generate a token and log in from the 'Test System' now.
Pull and Run the Image on the Test System
$ sudo docker pull kernelmastery/hello-python3
$ sudo docker run -p 80:80 kernelmastery/hello-python3
- Test: Make sure you can access the running application (server) from your web browser, either from a local web browser, or using a Public IP address, if you have one.
Now, let's say you need to make some changes. How do you push those changes to your Repository while allowing for version control? The answer is simple: Version Tags.
Rebuild, Retag, Repush
:<tag> to the end of your image name while building and tagging. E.g.:
$ sudo docker build --tag=hello-python3:v2 .
$ sudo docker tag hello-python3:v2 kernelmastery/hello-python3:v2
$ sudo docker push kernelmastery/hello-python3:v2
That's it! You should now be all set up to build, tag, push, pull, and, if you want, collaborate with others via Docker Hub.