HiveBrain v1.2.0
Get Started
← Back to all entries
snippetdockerMinor

How can I push multiple containers, created with docker-compose, to a registry

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
cancreatedwithdockerregistrypushcomposemultiplehowcontainers

Problem

I am using Jenkins pipeline and run a shell command to bring up my linked containers for testing. Once the testing is complete, I want to push the containers to a registry (I would prefer AWS ERC, but at this point I will take any working examples). What is the proper way to do this? Should each image go to a different repository? How can I get all of the containers created by the compose file pushed up? I have been attempting to get this done with the docker-compose push command, but I can't seem to get it working properly or find any decent examples.

Jenkinsfile

node('ec2-build-slave') {
    stage('Docker Build') {
        /* This builds the actual image; synonymous to
        * docker build on the command line */

        sh("docker network create aa_backend_network")
        sh("docker-compose up -d --build")
        //docker.build("$IMAGE")
    }
    stage ('Docker Push'){
        // /* This pushes the previously built image to the Amazon
        // * ECS Container Registry */
        sh("eval \$(aws ecr get-login --region us-west-2 --no-include-email | sed 's|https://||')")
        // docker.withRegistry(ECR_URL, ECR_CRED) {
        // docker.image(IMAGE).push()
        // }

        sh("docker-compose build")
        sh("docker-compose push")
    }
}
catch (exc) {
    currentBuild.result = "FAILED"
    throw exc
}
finally {
    // Success or failure, always send notifications
    notifyBuild(currentBuild.result)
    sh("docker-compose down -v")
    sh("docker network prune -f")
}
}
}


docker-compose

```
version: "2"
services:
db_setup:
networks:
- default
build: .
depends_on:
- db
container_name: db_setup
image: db_setup
command: python asteri_analytics_db.py
working_dir: /asteri_analytics_db/asteri_analytics_db
db:
networks:
- default
- outside
image: mongo:3.6.3
container_name: mongo_db
restart: always
environment:
MONGO_DATA_DIR: /data/db
MONGO_LOG_DIR: /dev

Solution

Just make sure the images you build all have the right names in terms of registry prefix and so on. If not you need to rename them accordingly.

Otherwise this task is pretty easy. To push all Images you build using a docker-compose file just use docker-compose push.

Make sure you are authorised to push to the registry (logged in etc.)

Context

StackExchange DevOps Q#3777, answer score: 3

Revisions (0)

No revisions yet.