Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Bitbucket to dockerhub to server deployments

BeingShashikant
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 6, 2019

Hi,

1. Without Docker --

We were not using the docker thing, till now. It was just coded commits, then using the bitbucket pipelines the server deployments. It's working very fine.

2. With Docker --

Now we want to start with docker with the proper industry standard of using it.

These are the steps we have done until now - 

1. Bitbucket repo created for a product.

2. Earlier we used to have a different repo for like backend, frontend, APIs, etc.

3. Now everything is inside the same repo with directory within the different folder, so each folder corresponds to a docker container or service.

4. So I have created the docker-compose file and added the configuration, it is working as expected on local and also on the server.

5. Please note that will now we are NOT using DockerHub for pushing or pulling the image. We are pulling the repo code onto the server and then running docker commands.

6. We know the step 5, may not the standard way of doing it.

7. So I have come across https://bitbucket.org/blog/bitbucket-pipelines-best-ci-cd-tool-docker-based-software

8. Now let me ask my question directly - How can I manage to push images onto our private docker hub account and also onto our server using bitbucket pipelines with just single click.

9. So is there any way by which whenever anyone commits the code merges into any branch- it should go on docker hub and also deploy on the server.

Above is just my context for explaining what I am looking for. I need help for understanding it correctly and doing it correctly.

 

Thanks,

1 answer

0 votes
Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 13, 2019

Hello Shashikant,

There's a lot in this question. So lets work through it incrementally. :) Sorry if I missed some details in this answer.

Now let me ask my question directly - How can I manage to push images onto our private docker hub account and also onto our server using bitbucket pipelines with just single click.

So to clarify, you want to push the code to your server and also create a Docker image to push to DockerHub?

You should be able to add in Docker commands into your Bitbucket Pipelines configuration. An example bitbucket-pipelines.yml would be:

pipelines:
default:
- step:
services:
- docker # This enables Docker in this step.
script:
- # Build and test the application as you currently do.
- # Upload code to your server as you currently do.
- docker login -u dockerhub_username -p $DOCKERHUB_PASSWORD # Login to private Dockerhub account
- docker build -t repo/imageName:tag . # Build the image
- docker push repo/imageName:tag # Push the image to your private Dockerhub account.

This will both push the code to your server, but also create and push a Docker image to your private DockerHub account. We have more detailed documentation available on using Docker inside of Bitbucket Pipelines.

I'll add, that if you're still relatively new to Docker you should gain some familiarity by practicing locally first. Here's a good guide for the basics: https://docs.docker.com/get-started/

So is there any way by which whenever anyone commits the code merges into any branch- it should go on docker hub and also deploy on the server.

Do you have a similar workflow in your "Without Docker" deployments at the moment? If so, you can reuse that workflow with the commands I provided above. Otherwise, you can use branch pipelines to handles this.

For example, this will automatically upload code to your server and push a Docker image to Dockerhub whenever new code is commited/merged to the master branch:

pipelines:
branches:
master:
- step:
services:
- docker # This enables Docker in this step.
script:
- # Build and test the application as you currently do.
- # Upload code to your server as you currently do.
- docker login -u dockerhub_username -p $DOCKERHUB_PASSWORD # Login to private Dockerhub account
- docker build -t repo/imageName:tag . # Build the image
- docker push repo/imageName:tag # Push the image to your private Dockerhub account.
default:
- step:
script:
- echo "All commits not on master will run this commit by default."

We have more information about branch workflows here: https://confluence.atlassian.com/bitbucket/branch-workflows-856697482.html

If you need more clarification, it would help me if you could also attach a copy of your current bitbucket-pipelines.yml file, which you are using for your "Without Docker" deployments. Just for some extra context.

Thanks,

Phil

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events