To push a Laravel Docker image to Docker Hub, build the image with a name that starts with your Docker Hub username, log in with docker login, and run docker push username/laravel-app:1.0.0. Tag the image with a version number, not only latest, so you can roll back. The steps below cover the build, tagging, login, push and a pull test.
I assume a Laravel 13 app (PHP 8.3 or newer) that already has a working Dockerfile. Pushing an image is useful when a server, a CI job or a teammate should pull a ready build instead of building it again.
What do I need before I start?
- Docker installed and running.
- A free Docker Hub account and a repository name in mind, for example
yourname/laravel-app. - A
Dockerfilein the project root and a.dockerignorefile.
Step 1: What should .dockerignore contain?
Keep secrets and bulky folders out of the image. A common starting point:
.git
.env
node_modules
vendor
storage/logs/*
storage/framework/cache/*
testsExcluding .env matters. A pushed image can be pulled by anyone if the repository is public, and even in a private repository you do not want secrets baked into layers. Install vendor inside the image with Composer instead of copying your local folder.
Step 2: How do I build the image?
docker build -t yourname/laravel-app:1.0.0 .The format is username/repository:tag. The tag is your version label. If you already built the image under another name, add a second name without rebuilding:
docker tag laravel-app:latest yourname/laravel-app:1.0.0Step 3: How do I log in to Docker Hub?
docker loginEnter your username and a password or a personal access token. A token is safer than your account password because you can limit and revoke it. In CI, store the token as a secret and pass it on standard input with --password-stdin so it does not appear in shell history:
echo "$DOCKERHUB_TOKEN" | docker login -u yourname --password-stdinStep 4: How do I push the image?
docker push yourname/laravel-app:1.0.0Docker uploads each layer once. Layers that already exist on Docker Hub are skipped, so later pushes are faster when only your application code changed. To also publish a moving tag:
docker tag yourname/laravel-app:1.0.0 yourname/laravel-app:latest
docker push yourname/laravel-app:latestI did not run these commands against a real Docker Hub account for this article. They follow the Docker CLI documentation.
Step 5: How do I prove the push worked?
- Open the repository page on Docker Hub and check that the tag
1.0.0is listed with a recent push time. - Remove the local copy:
docker rmi yourname/laravel-app:1.0.0. - Pull it back:
docker pull yourname/laravel-app:1.0.0. - Run it:
docker run --rm -p 8000:80 yourname/laravel-app:1.0.0and open the page. The exact port depends on how your image serves PHP.
Should the repository be public or private?
Use private for application code. A free Docker Hub account includes a limited number of private repositories, so check the current limits on your plan. Public is fine for open source projects, as long as no secret ever entered the image.
How should I name and version tags?
- Use semantic versions such as
1.4.2for releases. - Optionally add the short Git commit hash for traceability.
- Treat
latestas a convenience, not as something production depends on. - Never overwrite a version tag that was already deployed.
What are the common mistakes?
- Wrong image name. Without your username prefix, Docker tries to push to a repository you do not own and returns an access error.
- "denied: requested access to the resource is denied". You are not logged in, or the repository belongs to another account.
- Secrets in the image. A
COPY . .without a.dockerignorecan copy.envinto a layer. Check withdocker history. - Pushing a dev image. Build a production image with
composer install --no-devand optimised autoload. - Using only latest. You cannot tell what is deployed, and rollback is guesswork.
- Architecture mismatch. An image built on an Apple Silicon laptop may not run on an amd64 server. Build for the target platform with
docker buildx build --platform linux/amd64.
FAQ
How do I push a Laravel image to a private registry instead?
Include the registry host in the image name, for example registry.example.com/team/laravel-app:1.0.0, run docker login registry.example.com, then push.
Can I push from GitHub Actions?
Yes. Store the Docker Hub token as a repository secret and use the official Docker login and build-push actions. Keep the token scope as narrow as possible.
Does pushing include my database data?
No. An image contains the filesystem built from your Dockerfile. Data in volumes stays on the machine where the container ran.



