Fork of Docker in Docker (petazzo/dind), with Azure-cli installed.
You MUST run this in privileged mode. JPetazzo explains why in this blog post.
docker run -it --privileged -u root -v /var/run/docker.sock:/var/run/docker.sock davevoyles/dind-azurecli sh
-v /var/run/docker.sock:/var/run/docker.sock command mounts the socket of the EXTERNAL container to that of the INTERNAL container, so that you now have a shell inside of the container to run commands.
If you see all of this log info below, then you've stood up the outer Docker container.
Access the internal docker container
Now open a new terminal window to access the internal docker container.
Docker ps to list out the currently running docker images. Copy the ID# of the image we just ran. Test out the azure CLI with a simple
docker exec -it <ID# of image> az -h
Now you have access to the Azure CLI from within the internal docker container!
Using the Azure CLI to build containers
As an example, you can run the following command to:
- Build the react-boilerplate image from the code4clouds Azure Container Registry
- Log into an Azure Service Principal. You can read more about those here.
- Push that image to the Azure Container Registry
docker build --tag registryXYZ.azurecr.io/code4clouds/react-boilerplate:1.0 . az login --service-principal --username $ACRUSERNAME --password $ACRPASSWORD --tenant $ACRTENANT --allow-no-subscription az acr login --name registryXYZ docker push registryXYZ.azurecr.io/code4clouds/react-boilerplate:1.0'
Obviously you'd swap the user name, password, tenant and repository to match that of your own.