Home > Software engineering >  How to push docker image from local to azure environment?
How to push docker image from local to azure environment?

Time:06-15

I have a docker image and I can run the docker image as a container. But I have to bind two folders local to the docker container. And I do it like this:

 docker run -d -p 80:80 --name cntr-apache2 -v C:\xampp\htdocs\webscraper2/docker:/etc/apache2/sites-enabled/ -v C:\xampp\htdocs\webscraper2:/var/www/html/ docker_webcrawler2

and then I go to: localhost:80. And the app is running.

But now I want to deploy it to the azure environment.

So Logged in in the azure portal: azure login.

and in docker I logged in: docker login webadres.azurecr.io.

and then I did a push: docker push webaddres.azurecr.io/webaddress-webscraper:latest.

And I got this response:

latest: digest: sha256:7eefd5631cbe8907afb4cb941f579a7e7786ab36f52ba7d3eeadb4524fc5dddd size: 4909

And I made a web app for docker.

But now if I go to the url: https://docker-webaddress.azurewebsites.net

the index is empty. And that is logical. Because I didnt bind the two directories to the docker container in azure.

So my question is:

How now to bind the two direcories with azure docker?

Thank you

And this is my dockerfile:

FROM php:7.3-apache

# Copy virtual host into container
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf

# Enable rewrite mode
RUN a2enmod rewrite

# Install necessary packages
RUN apt-get update && \
    apt-get install \
    libzip-dev \
    wget \
    git \
    unzip \
    -y --no-install-recommends

# Install PHP Extensions
RUN docker-php-ext-install zip pdo_mysql


# Copy composer installable
COPY ./install-composer.sh ./


# Copy php.ini
COPY ./php.ini /usr/local/etc/php/

#COPY BaltimoreCyberTrustRoot.crt.pem /var/www/html/

EXPOSE 80

# Cleanup packages and install composer
RUN apt-get purge -y g   \
    && apt-get autoremove -y \
    && rm -r /var/lib/apt/lists/* \
    && rm -rf /tmp/* \
    && sh ./install-composer.sh \
    && rm ./install-composer.sh

# Change the current working directory
WORKDIR /var/www

#COPY composer.json composer.lock ./

#COPY --from=composer /usr/bin/composer /usr/bin/composer
#RUN composer install


# Change the owner of the container document root
RUN chown -R www-data:www-data /var/www


# Start Apache in foreground
CMD ["apache2-foreground"]

I had a docker-compose file. Like this:

version: '3'
services:
  web:   
    build: ./docker       
    container_name: dockeryiidisc
    ports:
      - 80:80
      - 443:443
    volumes:
      - C:\xampp\htdocs\webScraper/docker:/etc/apache2/sites-enabled/
      - C:\xampp\htdocs\webScraper:/var/www/html/ 

And then I didnt had to do this command:

docker run -d -p 80:80 --name cntr-apache2 -v C:\xampp\htdocs\webscraper2/docker:/etc/apache2/sites-enabled/ -v C:\xampp\htdocs\webscraper2:/var/www/html/ docker_webcrawler2

But is it possible that I upload this file to my git repository.

do a build of the container local.

And then I do a docker push to my azure docker container?

CodePudding user response:

One option is to use App Service persistent storage.

You need to enable the functionality first:

az webapp config appsettings set --resource-group <group-name> --name <app-name> --settings WEBSITES_ENABLE_APP_SERVICE_STORAGE=TRUE

Then create a mapping in a Docker Compose file even if you have a single container to deploy. The {WEBAPP_STORAGE_HOME} environment variable will point to /home in the App Service VM. You can use the Advanced Tools (Kudu) to create the folders and copy the needed files.

Wordpress:
  image: <image name:tag>
  volumes:
  - ${WEBAPP_STORAGE_HOME}/folder1:/etc/apache2/sites-enabled/
  - ${WEBAPP_STORAGE_HOME}/folder2:/var/www/html/ docker_webcrawler2

Documentation

Another option is to mount Azure Storage.

Note that mounts using Blobs are read-only and File Share are read-write.

Start by creating a storage account and a File Share.

Create the mount. I find that it's easier using the Portal. See how in the doc link below.

az storage share-rm create \
--resource-group $resourceGroupName \
--storage-account $storageAccountName \
--name $shareName \
--quota 1024 \
--enabled-protocols SMB \
--output none

Documentation

  • Related