You can follow steps below to push your docker image to your Docker Hub account.


Create a Docker Repository


Go to Docker Hub and create a new Docker Repository.


Docker Application Structure


hello$ tree
.
├── app
│   ├── a.php
│   └── b.php
└── docker
├── docker-compose.yml
├── .env
└── php
└── Dockerfile

Files


a.php


echo 'Hello a'.PHP_EOL;

b.php


echo 'Hello b'.PHP_EOL;

Dockerfile


FROM php:7.2-cli

RUN echo ${HOME}

CMD tail -f /dev/null

docker-compose.yml


version: '3'

services:

php:
build:
context: ./php
image: inanzzz/hello
hostname: php
volumes:
- ../app:/app:rw
working_dir: /app

.env


COMPOSE_PROJECT_NAME=hello

Create a Docker Image


I assume that you created a Docker image on your local environment. I've created a simple PHP-CLI docker application with docker compose and built with hello$ docker-compose up -d command. The result is shown below as follows.


$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
inanzzz/hello latest 72b7a2f74c24 12 minutes ago 368MB
php 7.2-cli 71c6a3058357 6 days ago 368MB

$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5353e38a3b60 inanzzz/hello "docker-php-entrypoi…" 12 minutes ago Up 12 minutes hello_php_1

$ docker network ls
NETWORK ID NAME DRIVER SCOPE
3490cb99ced3 hello_default bridge local

Login to Dokcer Hub


$ docker login
Username: inanzzz
Password:

Login Succeeded

Push


$ docker push inanzzz/hello:latest
The push refers to repository [docker.io/inanzzz/hello]
1704ec493095: Mounted from library/php
2ced8dda1e70: Mounted from library/php
latest: digest: sha256:123b7038fc8c450332090de16a71fb82f5b3d03ec89e4c11be9ffe9312912345 size: 2202

Tagging


If you wish you can tag your image and push tagged version of the image.


$ docker tag inanzzz/hello:latest inanzzz/hello:0.0.1

$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
inanzzz/hello 0.0.1 72b7a2f74c24 35 minutes ago 368MB
inanzzz/hello latest 72b7a2f74c24 35 minutes ago 368MB

$ docker push inanzzz/hello:0.0.1
The push refers to repository [docker.io/inanzzz/hello]
1704ec493095: Layer already exists
2ced8dda1e70: Layer already exists
0.0.1: digest: sha256:123b7038fc8c450332090de16a71fb82f5b3d03ec89e4c11be9ffe93129c1234 size: 2202

Result