DEV Community

GaMa
GaMa

Posted on Edited on

Creating a Docker image and upload it to Docker Hub

Creating the Docker image

I'm going to use a Docker image to be able to use multiple github accounts from the same machine without so much trouble. To keep the image small I will use Alpine as a base image and only install the basics: git, vim, openssh-client.

In order to build the image we need to create a new file called Dockerfile and write the following:

FROM alpine:latest

LABEL maintainer="@ech0Server"

RUN apk update
RUN apk add git vim openssh-client
⚽ Live Match: echserver/creating a docker image and upload it to docker hub - Pertandingan Hari Ini ⚽ Live Match: echserver/creating a docker image and upload it to docker hub - Pertandingan Hari Ini

Then, to build the docker image run:

docker build -t username/imagename:latest .
⚽ Live Match: echserver/creating a docker image and upload it to docker hub - Pertandingan Hari Ini ⚽ Live Match: echserver/creating a docker image and upload it to docker hub - Pertandingan Hari Ini

This command not only will build the image but it will tag it with the -t option, for my case I did:

docker build -t ech0server/multigitaccount:latest .
⚽ Live Match: echserver/creating a docker image and upload it to docker hub - Pertandingan Hari Ini ⚽ Live Match: echserver/creating a docker image and upload it to docker hub - Pertandingan Hari Ini

I will assume that you already have a Docker Hub account or create a docker hub account, then:

$ export DOCKER_ID_USER="username"
$ docker login #it will prompt you for your username and password
⚽ Live Match: echserver/creating a docker image and upload it to docker hub - Pertandingan Hari Ini ⚽ Live Match: echserver/creating a docker image and upload it to docker hub - Pertandingan Hari Ini

If you followed the previous instructions your image should be already tagged, if not then you can tag your image by:

docker tag my_image $DOCKER_ID_USER/my_image
⚽ Live Match: echserver/creating a docker image and upload it to docker hub - Pertandingan Hari Ini ⚽ Live Match: echserver/creating a docker image and upload it to docker hub - Pertandingan Hari Ini

Finally we can push the Docker image to the Hub:

docker push ech0server/multigitaccount:latest
⚽ Live Match: echserver/creating a docker image and upload it to docker hub - Pertandingan Hari Ini ⚽ Live Match: echserver/creating a docker image and upload it to docker hub - Pertandingan Hari Ini

After that is completed you can go to: https://hub.docker.com/u/username and see that the image was successfully uploaded.

My image can be found here: https://hub.docker.com/r/ech0server/multigitaccount/

And you can pull it by doing:

docker pull ech0server/multigitaccount
⚽ Live Match: echserver/creating a docker image and upload it to docker hub - Pertandingan Hari Ini ⚽ Live Match: echserver/creating a docker image and upload it to docker hub - Pertandingan Hari Ini

Top comments (0)