I tried do run a docker in pipeline ,first i tried to use documentation : https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/docker-v2?view=azure-pipelines&viewFallbackFrom=azure-devops&tabs=yaml#troubleshooting but still got errors
Its looks like my pipeline properly download a docker file but when i try to exec any command in docker file i got errors
steps:
- checkout: self
clean: true
fetchDepth: full
- task: Docker@2
displayName: Login to ACR
inputs:
containerRegistry: 'Docker'
command: 'login'
- script: |
docker run -d docker.io/Docker/Sample-docker-image
displayName: 'Run Docker'
- task: Docker@2
inputs:
containerRegistry: 'Docker'
command: 'start'
container: 'Docker/Sample-docker-image'
when i run this i got
Error response from daemon: No such container: ***/Docker/Sample-docker-image
Error: failed to start containers: ***/Docker/Sample-docker-image
##[error]Error response from daemon: No such container: ***/Docker/Sample-docker-image
##[error]Error: failed to start containers: ***/Docker/Sample-docker-image
##[error]The process '/usr/bin/docker' failed with exit code 1
How to handle and properly use a docker ? Im doing something wrong in this yml ?
Edit:
i added
container_id=$(docker run -d Docker/Sample-docker-image)
echo "Container ID: $container_id"
echo "##vso[task.setvariable variable=container_id]$container_id"
container_id=$(echo $container_id)
while [[ "$(docker inspect -f '{{.State.Status}}' $container_id)" != "running" ]]; do
docker inspect $container_id
docker logs $container_id
sleep 10
docker ps -a
done
and it shows docker starts as exited status. i tried locally and every image works as expected
2
Answers
Thank you for answers. I made mistake only thing which i missed is a letter -t
This solved a issue, container is running and im able to run docker exec
Below are the steps to execute a command on the docker image.
Step 1: Create a service connection to the container registry if it is private. For public registries, a service connection is not required.
Step 2: Specify the container in the resources section of the pipeline and add the service connection name as the endpoint as shown below.
Step 3: Add the container resource as the target to the steps you would like to execute on the docker container.
Below is the full pipeline code.
When I run this pipeline, it first fetches the image from the container registry and then start the container. The first step will execute on the azure agent while the second step will execute on the docker container.
References: