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
Enter fullscreen mode Exit fullscreen mode

Then, to build the docker image run:

docker build -t username/imagename:latest .
Enter fullscreen mode Exit fullscreen mode

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 .
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Finally we can push the Docker image to the Hub:

docker push ech0server/multigitaccount:latest
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Top comments (0)