AgustinCB / docker-api

Docker Remote API driver for node.js. It uses the same modem than dockerode, but the interface is promisified and with a fancier syntax.
GNU General Public License v3.0
303 stars 51 forks source link

You have to remove (or rename) that container to be able to reuse that name. #62

Open vinay-appup opened 5 years ago

vinay-appup commented 5 years ago

{ Error: (HTTP code 409) unexpected - Conflict. The container name "/test" is already in use by container "70f415ef635ece943bee6c935f78b0912a88573e95ab8f7fe9d24d397e5e8379". You have to remove (or rename) that container to be able to reuse that name.

It is taking some time to delete the container(1000 ms). How to resolve this.

docker.container.list()
                    .then(containers => containers.forEach(function(value, i) {
                        if (value.data.Names.includes('/test')) {
                            value.delete({force: true})
                        }
                    })).then( docker.container.create({
                                Image: '**',
                                name: 'test',
                                Env: [  ],
                                "HostConfig": {
                                    "NetworkMode": "host"
                                }
                            })
                            .then(container => container.start())
                            .catch(error => console.log(error)));
AgustinCB commented 3 years ago

Hah! Thank you so much! I will fix existing code to take this into account.