vrijdag 27 september 2019

Docker II

Some Docker commands:

Build a new container:
docker build -t mycontainer .
Start the container
docker run mycontainer
Start the container detached (returning containerID)
docker run --detach mycontainer
Stop container
docker stop mycontainer
Restart container (silent)
docker start mycontainer
Restart container (with console attached)
docker attach mycontainer
Keep data changes made on container
docker commit mycontainer
Execute command on running container

docker exec -it mycontainerID bash remove all containers: docker rm $(docker ps -a -q)

To show only running containers use the given command:
Commit a change made in a running container: docker commit CONTAINER_ID myContainer

docker ps

To show all containers use the given command:

docker ps -a
With environment vars: docker run --env-file ./env.list mycontainer

dinsdag 24 september 2019

Docker

Docker seems to be a sophisticated way to test server applications, and to bring them in production. Docker can host various operating systems.

To have Docker on a Windows 10 system, one should have Windows Pro on hardware that supports virtualization (I guess most current hardware will support it. Here are the exact specs.)

The Docker container should eventuallu run on Azure, so I followed this tutorial. After installing Docker Desktop, it is necessary to download a basic template of a Docker container, probably most often retrieved from GitHub. So  after installing GIT, I choose to download the Diango container, as mentioned in the tutorial. This has the Python and Flask software included.

The Dockerfile in this download contains the build configuration for the container. After updating the requirements.txt file for Python I tried to build the container. 
However I had an error installing the pyodbc: In the end I needed a quite complicated command to have ODBC installed correctly.


FROM python:3.6
# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app

# unixODBC
RUN apt-get update && \
    apt-get install -y apt-transport-https && \
    curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
    curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
    apt-get update && \
    ACCEPT_EULA=Y apt-get install msodbcsql17 unixodbc-dev -y
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 8080

# Define environment variable
ENV NAME World

# Run app.py when the container launches
CMD ["python", "app.py"]



The build commando is done in a powershell prompt (don't forget the dot at the end):

PS E:\docker_prep\docker-django-webapp-linux> docker build -t mycontainer_ai .

And to run:

PS E:\docker_prep\docker-django-webapp-linux> docker run -p 8080:8080 mycontainer_ai


dinsdag 17 september 2019

And then to Azure II

We want  customers to specify their own place to have their database, and to store the machine learning file. 
The database connection is clear: just specify the connection string to the Azure database, and you're ready to go (well, use pyodbc)

Azure now has many services to store something, and it is not immediately clear which one to use for this purpose.

After looking around, it seemed that the Workspace I created earlier is also a blob storage. Here you can find the accountname to use, and accesskey:


So after installing the correct packages, the code below worked.


pip install azure-storage-blob azure-mgmt-storage from azure.storage.blob import BlockBlobService, PublicAccess

blob_service
= BlockBlobService('[your account name]','[your access key]')

blob_service
.create_container(
   
'mycontainername',
    public_access
=PublicAccess.Blob
)

blob_service
.create_blob_from_bytes(
   
'mycontainername',
   
'myblobname',
    b
'hello from my python file'
)
print(blob_service.make_blob_url('mycontainername', 'myblobname'))
The example code from here shows how to download to file
block_blob_service.get_blob_to_path(container_name, local_file_name, full_path_to_file2)

and upload:

block_blob_service.create_blob_from_path(container_name, local_file_name, full_path_to_file)