Docker container cannot curl, invalid SSL version number

I am developing behind the company's proxy server using Linux Mint Sylvia (Docker was installed via Xenial Ubuntu 16.04.3 source).

$ docker -v Docker version 17.12.1-ce, build 7390fc6 

I followed the steps below to upload some images via dockers.

My http-proxy.conf:

 $ cat /etc/systemd/system/docker.service.d/http-proxy.conf [Service] Environment="HTTP_PROXY=http://my_user: my_pass@company _proxy:3128/" Environment="HTTPS_PROXY=https://my_user: my_pass@company _proxy:3128/" Environment="NO_PROXY=localhost,127.0.0.0/8" 

My /etc/default/docker :

 # If you need Docker to use an HTTP proxy, it can also be specified here. #export http_proxy="http://127.0.0.1:3128/" export http_proxy="http://my_user: my_pass@company _proxy:3128" export https_proxy="https://my_user: my_pass@company _proxy:3128" export HTTP_PROXY="http://my_user: my_pass@company _proxy:3128" export HTTPS_PROXY="https://my_user: my_pass@company _proxy:3128" 

I need to run curl inside an Alpine multi-stage container, for simplicity I created this simple image, similar to what I am trying to execute, and has the same error.

 FROM alpine:3.7 ENV HTTP_PROXY http://my_user: my_pass@company _proxy:3128 ENV HTTPS_PROXY https://my_user: my_pass@company _proxy:3128 RUN apk add --no-cache curl CMD ["curl","-v","--tlsv1","https://www.docker.io/"] 

Built with

 $ docker build --network host --rm -t test/alpine:curl . 

Work without --network host .

 $ docker run --rm test/alpine:curl % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Could not resolve proxy: company_proxy * Closing connection 0 curl: (5) Could not resolve proxy: company_proxy 

Work with --network host .

 $ docker run --network host --rm test/alpine:curl % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 10.2.255.0... * TCP_NODELAY set * Connected to company_proxy (10.2.255.0) port 3128 (#0) * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/ssl/certs/ca-certificates.crt CApath: none * TLSv1.2 (OUT), TLS handshake, Client hello (1): } [233 bytes data] * error:1400410B:SSL routines:CONNECT_CR_SRVR_HELLO:wrong version number 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 * Closing connection 0 curl: (35) error:1400410B:SSL routines:CONNECT_CR_SRVR_HELLO:wrong version number 

I start with Docker and tested this image on two Wi-Fi networks (both without a proxy), the containers worked just fine. Any tips on what might cause this SSL error?


Edit: This is my original problem, I have a multi-stage docker image that runs go code to spin something from firebase.

 // main.go package main import ( "os/exec" "os" "log" ) func main() { c := exec.Command("curl","--tlsv1","-kv","-X","PATCH","-d",`{"something" : "something"}`, `https://<firebase-link>`); c.Stdout = os.Stdout c.Stderr = os.Stderr err := c.Run() checkerr(err) } func checkerr(err error) { if err != nil{ log.Fatal(err.Error()) panic(err) } } 

Original Docker File:

 # This image only builds the go binaries FROM golang:1.10-alpine as goalpine-image ENV HTTP_PROXY http://my_user: my_pass@company _proxy:3128 ENV HTTPS_PROXY https://my_user: my_pass@company _proxy:3128 ENV FULL_PATH /go/src/<project-name> WORKDIR $FULL_PATH # Add the source code: ADD . $FULL_PATH # Build it: RUN cd $FULL_PATH \ && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/<project-name> # This image holds the binaries from the previous FROM alpine RUN apk add --no-cache bash curl\ && mkdir build ENV WORD_DIR=/build WORKDIR WORK_DIR COPY --from=goalpine-image /go/src/<project-name>/bin ./ CMD ["./<project-name>"] 
+5
source share
1 answer

I edited my question to learn more about my original problem, strange, the problem is still stored in the image of the toy. So, if someone comes across this problem again, this is what I managed to solve.

Multistage docker file. It seems that both stages should have access to proxy envs.

 # This image only builds the go binaries FROM golang:1.10-alpine as goalpine-image ARG http_proxy ARG https_proxy ENV HTTP_PROXY $http_proxy ENV HTTPS_PROXY $https_proxy # Build envs ENV FULL_PATH /go/src/<project-name> WORKDIR $FULL_PATH # Add the source code: ADD . $FULL_PATH # Build it: RUN cd $FULL_PATH \ && apk update \ && apk add --no-cache curl \ && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/<project-name> # This image holds the binaries from the previous FROM alpine:3.7 ENV HTTP_PROXY $http_proxy ENV HTTPS_PROXY $http_proxy RUN apk update \ && apk add --no-cache bash curl\ && mkdir build ENV WORD_DIR=/build WORKDIR WORK_DIR COPY --from=goalpine-image /go/src/<project-name>/bin ./ CMD ["./<project-name>"] 

Construction:

Be sure to set http_proxy and https_proxy as environment variables, mine are in /etc/profile .

 docker build --rm --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy --network host -t <project-name>:multi-stage . 

Duration:

 docker container run --rm --network host <project-name>:multi-stage 
0
source

Source: https://habr.com/ru/post/1275710/


All Articles