Kayes
Kayes

Reputation: 592

How can I docker commit azure container instance to azure container registry

We have ansible configured to deploy our various applications on IIS environment. I am trying to create a docker image of deployed applications so that I can just start up containers as we need for testing and otherwise.

I am planning to build on the Windows IIS image, start the container on azure, run our ansible to install everything on the server, then save the image on container.

I cannot find any documentation on how I can docker commit the container image into our private azure container registry.

Is it possible?

Upvotes: 1

Views: 1006

Answers (2)

Yasin Amini
Yasin Amini

Reputation: 255

I'm assuming your code is in the Github repo(the procedure is the same if you're using other repos like Bitbucket and etc.)

In the root of your repo, you can create .github folder, and create another folder in the name of workflows You can place your yml files inside this folder so the github know where to look for changes: I'm creating simple example here:

# This is your mydeployment.yml file: 

name: Publish IIS

# Configures this workflow to run every time a change is changed on a path.
on:
  push:
    paths:
      - 'path/to/mypackages'
  pull_request:
    paths:
      - 'path/to/mypackages'
# on:
#   push:
#     branches: ['main'] #you define your branch here
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
  deploy-IIS-to-ACR:
    runs-on: ubuntu-20.04
    # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
      # 
    steps:
    - name: Checkout repository
      uses: actions/checkout@v1
    # Uses the `docker/login-action` action to log in to the Container #registry registry using the account and password that will publish the #packages. Once published, the packages are scoped to the account defined here.
    - name: Log in to the Container registry
      uses: Azure/docker-login@v1
      with:
        login-server: myregistry.azurecr.io
        username: ${{ secrets.REGISTRY_USERNAME }}
        password: ${{ secrets.REGISTRY_PASSWORD }}
    - name: build the image
      run: |
        docker build --file "Path/to/your/docke" -t myregistry.azurecr.io/samples/nginx .
        docker push myregistry.azurecr.io/samples/nginx

The credentials for logging into the ACR can be placed inside the github secrets as environmental variables. As you can see in the documentation, you have quite a lot's of flexibility in configuration of building your image. Check this

Upvotes: 0

Nathan Lynch
Nathan Lynch

Reputation: 485

If you have an existing Docker registry in azure you should be able to use the az acr login --name myregistry command to authenticate to it https://learn.microsoft.com/en-us/azure/container-registry/container-registry-get-started-docker-cli. Make sure you have a registry created for the container image you want to push up.

Next, you can run the container in azure and do all the installation you want. SSH or RDP into the instance in Azure that is running this container. Now run docker ps and find the container id for the correct container. Next, use docker commit <container id> myregistry.azurecr.io/samples/nginx.

Then, just docker push myregistry.azurecr.io/samples/nginx

Also not sure what your use case is, but starting a container in order to modify and commit it in that way seems like an atypical use case for Docker since the build isn't reproducible via the Dockerfile. Looks like there are ways to replace Dockerfiles using Ansible playbooks with something like ansible-containers https://docs.ansible.com/ansible-container/ so you might want to take a look at that(I've never used this tool).

Upvotes: 1

Related Questions