Can't install pip packages inside a docker container with windows - windows

Dockerfile
# Use an official Python runtime as a base image
FROM python:3.8.1-windowsservercore
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# 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 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "app.py"]
It is giving me this error
How to solve this proxy network error? I got solution for linux but for windows 10 i am not able to find any answer. I am using latest docker for windows.

If you have n/w proxy in between use below command :
docker build --no-cache --build-arg HTTP_PROXY=http://xx.xx.xx.xx:xx --build-arg HTTPS_PROXY=http://xx.xx.xx.xx:xx --network=host -t helloworkapp .
If you don't have any proxy use this command (use host n/w for downloading packages):
docker build --no-cache --network=host -t helloworkapp .

Related

How to run streamlit through docker?

I want to run the streamlit through docker. I did not find any official image. Can someone please guide me with the steps required to achieve this or Dockerimage for streamlit?
Here is the details
Operating System: Windows 10 Home
Docker version 19.03.1
Streamlit, version 0.61.0
You can look into this docker hub image.
docker run -it -p 80:80 --entrypoint "streamlit" marcskovmadsen/awesome-streamlit:latest run app.py
Not sure about the streamlit version but you can create one base on this Dockerfile.
Or you can explore streamlit-docker, working for me on my local system.
Quick Setup (own image)
Dockerfile
# Nicked from: https://github.com/markdouthwaite/streamlit-project/blob/master/Dockerfile
FROM python:3.8.4-slim
RUN pip install -U pip
COPY requirements.txt app/requirements.txt
RUN pip install -r app/requirements.txt
# copy into a directory of its own (so it isn't in the toplevel dir)
COPY . /app
WORKDIR /app
CMD ["python", "-m", "streamlit.cli", "run", "main.py", "--server.port=8080"]
EXPOSE 8080
requirements.txt
Then, in the same directory, example contents of the requirements.txt file:
streamlit==0.76.0
pandas==1.2.1
numpy==1.19.5
docker-compose.yml
In a directory above your Dockerfile and source code, you can add:
version: "3.7"
services:
streamlit:
build:
context: streamlit/
volumes:
- ./streamlit:/app
ports:
- 8080:8080

Run docker with aliased port and access to bash

I'm trying to start a docker snapshot and connect to it via bash but also alias its port so I can access it from my local system at localhost:3333, this is what I have:
docker run -d -p 3333:3000 -t -i mysnapshot /bin/bash
However while it does start the container image it doesn't connect to it via bash
This is the output it generates:
3c86ca433d645c6c11315e89bbeaf89f072e2d1fa83213d4c4256c4a1af98322
and this is the dockerfile used to build the image:
FROM node:10
Setting working directory. All the path will be relative to WORKDIR WORKDIR /usr/src/app
Installing dependencies COPY package*.json ./ RUN npm install
Copying source files COPY . .
Building app
RUN npm run build
Running the app CMD [ "npm", "start" ]
You used -d option in docker run command, which will run the container in detached mode in the background.
Please check this out.
To get into the bash run
docker exec -it <conatiner-id> /bin/bash
where <container-id> can be retrieved from docker ps output.
Also as per your dockerfile you want npm start to be the first process in the container, so while running docker run command don't specify /bin/bash because it will override the CMD npm start mentioned in the dockerfile.
Hope this helps, let me know.
It seems you may need to overwrite your entrypoint because last line of your dockerfile mention your start command is npm start.
Also, -d detached mode is not needed.
Try this one:
docker run -it -p 3333:3000 --entrypoint=/bin/bash mysnapshot

permission issue with docker under windows

I'm using this scheme :
1/ I'm working on windows 7
2/ I'm using vagrant to mount a "ubuntu/trusty64" box
3/ I apt-get install ansible
4/ I install docker and docker-compose with ansibe
5/ I create a docker image with this dockerfile :
FROM php:7-apache
MAINTAINER Bruno DA SILVA "bruno.dasilva#foo.com"
COPY containers-dirs-and-files/var/www/html/ /var/www/html/
WORKDIR /var/www/html
6/ I run it :
sudo docker build -t 10.100.200.200:5000/pimp-hello-world .
sudo docker run -p 80:80 -d --name test-php 10.100.200.200:5000/pimp-hello-world
7/ apache can't display the page, I have to add :
RUN chmod -R 755 /var/www/html
to the dockerfile in order to have it visible.
so here is my question : can I handle files permission while working on windows (and how)? Or do I have to move under linux?
This happens in Linux. Docker copies the files and put root as owner. The only way I have found to overcome this without using chmod, is archiving the files in a tar file and then use
ADD content.tgz /var/www/html
It will expand automatically
Regards

Having problems deploying an go app to docker

Hi I am pretty new to go, and this is my first time working with docker to package an app into a container. I am working on a linux VM where the app is located under dir: /home/core/app/app-name In the dir app-name there is the main.go program and the Dockerfile. The Dockerfile contains this:
FROM golang:latest
RUN mkdir /app
ADD . /home/core/app/app-name
WORKDIR /app/app-name
RUN go build -o main .
CMD ["/app/main"]
EXPOSE 8080
I have tried running from dir /home/core/app/app-name:
docker build -t app-image .
But I got this error:
can't load package: package .: no buildable Go source files in /app/stars-app
The command '/bin/sh -c go build -o main .' returned a non-zero code: 1
What am I doing wrong?
Edit:
I got was able to build the image on my windows machine with the Dockfile:
FROM golang:latest
Add . /app/app-name
EXPOSE 8080
CMD ["/app/app-name/main"]
And by running:
docker build -t star-image .
I can see the image when I run "docker images", but when I try to run it using:
docker run -p 3000:8080 --name goapp --rm app-name
I get this error:
docker: Error response from daemon: Container command '/app/app-name/main' not found or does not exist..
This might work for you...
The GOPATH for the image is set to /go
install your source(s) under /go/src
given the gopath is set and sources are within the GOPATH
setting the working directory to /app
execute the build and the output should be present in the working
directory
Dockerfile
FROM golang:latest
ADD ./app /go/src/app
RUN mkdir /app
WORKDIR /app
RUN go build -o main app/app-name
CMD ["/app/main"]
EXPOSE 8080
app/app-name/main.go
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
docker build -t app-image .
docker run app-image
output
hello, world
I had problems with this too but somehow based on this guide, this worked for me.
# ...AS builder ...
FROM golang:1.14
WORKDIR /go/src/app
# In your case, ./main.go or just .
COPY ./server.go .
COPY --from=builder ./app/build .
RUN go get -d -v ./...
RUN go install -v ./...
CMD ["app"]

How to specify current directory for Docker?

I'm following this part of the Docker tutorial (on a Mac): https://docs.docker.com/mac/step_four/. I'm getting an error when I try to run the docker-whalesay image because it can't find fortunes.
I started off in the Dockerfile using /user/games/fortunes. Then I changed to just fortunes. Neither work.
How do I specify in the Dockerfile to use the current folder (mydockerbuild)?
The Dockerfile in that example does not rely on files that are present on your computer, basically, the only steps needed are;
Create an empty directory (you named it mydockerbuild)
mkdir mydockerbuild
Change to that directory
cd mydockerbuild
Create a Dockerfile
Edit the Dockerfile to look like this;
FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay
Build the Dockerfile, and name the built image "docker-whale"
docker build -t docker-whale .
Run the image you just built
docker run --rm docker-whale
The /usr/games/fortunes path in the Dockerfile is referring to a path inside the container. In this case, the /usr/games/fortunes is created by the fortune package that it's installed by apt-get install -y fortunes.

Resources