Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Conflict. The container name "/django-todolist-prod" is already in use

Olá pessoal, tudo bem? Me deparei com o mesmo problema aqui...

Saída do console
Started by user Rafael Carreiro
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/todo-list-producao
provisioning config files...
copy managed file [.env-prod] to file:/var/lib/jenkins/workspace/todo-list-producao/.env
[todo-list-producao] $ /bin/sh /tmp/jenkins11804960267710059724.sh
docker: Error response from daemon: Conflict. The container name "/django-todolist-prod" is already in use by container "eda4ced86b28ce55795ca49e8ca3b75812a98feab446c33a4d85024ce0d27822". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
django-todolist-prod
dbe3e998f6cb4d7b9426449c9535d99dda966a8f791abe34ecaea452d7153270
docker: Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:75: mounting "/var/lib/jenkins/workspace/todo-list-producao/.env" to rootfs at "/usr/src/app/to_do/.env" caused: mount through procfd: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
Build step 'Execute shell' marked build as failure
[Slack Notifications] found #1 as previous completed, non-aborted build
[Slack Notifications] will send OnEveryFailureNotification because build matches and user preferences allow it
Finished: FAILURE
  • docker: Error response from daemon: Conflict. The container name "/django-todolist-prod" is already in use by container "eda4ced86b28ce55795ca49e8ca3b75812a98feab446c33a4d85024ce0d27822".

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

Como sugerido na mensagem de erro, segui a lógica da pipeline anterior editando o shell script utilizado, adicionando como primeiro passo a remoção do container django-todolist-prod.

Ficou assim:

#!/bin/sh


docker rm -f django-todolist-prod


{ 
    docker run -d -p 80:8000 -v /var/run/mysqld/mysqld.sock:/var/run/mysqld/mysqld.sock -v /var/lib/jenkins/workspace/todo-list-producao/.env:/usr/src/app/to_do/.env --name=django-todolist-prod $image:latest

} || { # catch
    docker rm -f django-todolist-prod
    docker run -d -p 80:8000 -v /var/run/mysqld/mysqld.sock:/var/run/mysqld/mysqld.sock -v /var/lib/jenkins/workspace/todo-list-producao/.env:/usr/src/app/to_do/.env --name=django-todolist-prod $image:latest
}    

Após buildar novamente surgiu outro problema:

Started by user Rafael Carreiro
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/todo-list-producao
provisioning config files...
copy managed file [.env-prod] to file:/var/lib/jenkins/workspace/todo-list-producao/.env
[todo-list-producao] $ /bin/sh /tmp/jenkins13658375700380712107.sh
django-todolist-prod
609915b8c04f25451c96af87c6ab3cacf23d298b92c2f37779e86d715abd1fcc
docker: Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:75: mounting "/var/lib/jenkins/workspace/todo-list-producao/.env" to rootfs at "/usr/src/app/to_do/.env" caused: mount through procfd: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
django-todolist-prod
e28ce4ea9534c6ba264e433cfe722baca929928b4fe968c8afc90a2c29556860
docker: Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:75: mounting "/var/lib/jenkins/workspace/todo-list-producao/.env" to rootfs at "/usr/src/app/to_do/.env" caused: mount through procfd: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
Build step 'Execute shell' marked build as failure
[Slack Notifications] found #2 as previous completed, non-aborted build
[Slack Notifications] will send OnEveryFailureNotification because build matches and user preferences allow it
Finished: FAILURE
  • failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:75: mounting "/var/lib/jenkins/workspace/todo-list-producao/.env" to rootfs at "/usr/src/app/to_do/.env" caused: mount through procfd: not a directory: unknown:
  • Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
1 resposta
solução!

Descobri qual era o problema, talvez seja necessário uma correção no arquivo disponibilizado na aula.

Segue a imagem do build realizado com sucesso: https://i.imgur.com/dqCirlf.png


A solução foi alterar o caminho do volume nos comandos docker, ao invés de:

  • /var/lib/jenkins/workspace/todo-list-producao

Ficou:

  • /var/lib/jenkins/workspace/jenkins-todo-list-producao

Adicionando apenas o jenkins- no caminho.


Esse shell ficou assim:

#!/bin/sh
{ 
    docker run -d -p 80:8000 -v /var/run/mysqld/mysqld.sock:/var/run/mysqld/mysqld.sock -v /var/lib/jenkins/workspace/jenkins-todo-list-producao/.env:/usr/src/app/to_do/.env --name=django-todolist-prod $image:latest

} || { # catch
    docker rm -f django-todolist-prod
    docker run -d -p 80:8000 -v /var/run/mysqld/mysqld.sock:/var/run/mysqld/mysqld.sock -v /var/lib/jenkins/workspace/jenkins-todo-list-producao/.env:/usr/src/app/to_do/.env --name=django-todolist-prod $image:latest
}

Output do Job finalizado com sucesso:

Started by user Rafael Carreiro
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/todo-list-producao
provisioning config files...
copy managed file [.env-prod] to file:/var/lib/jenkins/workspace/todo-list-producao/.env
[todo-list-producao] $ /bin/sh /tmp/jenkins17142210744045465362.sh
docker: Error response from daemon: Conflict. The container name "/django-todolist-prod" is already in use by container "a3092d6afdd9e2e02a1431d5008425082fefca014614e0c5fc0fec484e61af68". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
django-todolist-prod
c9ae3b157af5808ebd99c4aa059995f7b831d4d400e3404c2d7a93748d87db15
[Slack Notifications] found #9 as previous completed, non-aborted build
[Slack Notifications] will send OnSuccessNotification because build matches and user preferences allow it
Finished: SUCCESS

Espero que ajude os próximos que tiverem este problema nesta etapa do curso!