Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to run shell script to pull image from dockerhub and run it

Hi, I am creating a pipeline, and so far I've been able to to create the image and push it to docker hub. 

Now I need to log in to my EC2 instance, pull the image and run it. For that I have a shell script: 

#!bin/bashsudo docker psecho 'Login in to docker'aws ecr get-login-password |  - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
'Fetching latest image'sudo docker pull juanibe/api:latestecho 'Stoping current container'sudo docker stop cont_docker_app_test
echo 'Removing old container'sudo docker rm cont_docker_app_test-old
echo 'Rename stoped container'
sudo docker rename cont_docker_app_test cont_docker_app_test_old
echo 'Starting new container'sudo docker run -d --name cont_docker_app_test -p 443:3333 -p 8001:8001 --link my-mongo-testing:my-mongo-testing juanibe/api:latest


And I have this yml file for bitbucket:

image: atlassian/default-image:latest
pipelines: default: - step: services: - docker script: - export IMAGE_NAME=juanibe/vinimayapi:$BITBUCKET_COMMIT - docker build -t $IMAGE_NAME . - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD - docker push $IMAGE_NAME


Where can I run the script?? 

1 answer

0 votes

Hi @Juan Ignacio Benito and welcome to the community.

One option is to commit and push your script to your repository, and then include in the yml file a command to execute this script.

The other option is to add the commands of your script in your yml file.

For both options, you can either do this on the existing step and script in your yml file, or you can add a second step and add the commands there.

Just a note that you'll need to remove 'sudo' from the script/commands. You can't use sudo in Pipelines and you don't need to, as when you are running the image you are root.

If you have any questions, please feel free to let us know!

Kind regards,

Thank you very much Theodora! It worked as expected.


I have one question left.


I need to add environment variables (the ones that I have in the .env file) for the source code. Is there any way to hide them and use them without commiting the .env file to the repo?


Thank you again!

Hi Juan,

You are very welcome, I'm glad to hear that this worked!

Regarding variables, you can add variables either from the Repository settings ( > option Repository variables in the Pipelines section), if you want them to be available for this repo only, or at the workspace level (from workspace Settings > Workspace variables), if you want them to be available in all repos of this workspace.

When you create a variable you'll see a checkbox with the label Secured. If you select that, the variable's value won't be visible (and if you attempt to print it during the Pipelines build, its value still won't be shown).

Is this something that works for you?

Kind regards,

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

📣 Calling Bitbucket Data Center customers to participate in research

Hi everyone, Are you Bitbucket DC customer? If so, we'd love to talk to you! Our team wants to dive deep to understand your long-term plans regarding Bitbucket DC and Atlassian Cloud. Do you plan...

217 views 2 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you