Browser start from Docker

Asked by At

I have a python script running from Docker container. This script requires Google authorization procedure to work with API. How to trigger browser start in container to go to authorization page and pass it?

I am working with Docker Toolbox. Docker version 18.03.0-ce, build 0520e24302 docker-compose version 1.20.1, build 5d8c71b2

$ docker run -it  -e DISPLAY=$DISPLAY docker_script
/usr/local/lib/python3.7/site-packages/requests/ RequestsDependencyWarning: urllib3 (1.25.2) or chardet (3.0.4) doesn't match a supported version!
13:36:16.09: script service v1.14 b1
/usr/local/lib/python3.7/site-packages/oauth2client/ UserWarning: Cannot access /app/.credentials/google-drive-credentials.json: No such file or directory

Your browser has been opened to visit:

If your browser is on a different machine then exit and re-run this
application with the command-line parameter


1 Answers

Community On

Today i have managed to pass Google authorization from Docker container. I am using this construction:

def get_credentials():

    home_dir = os.path.expanduser('~')
    credential_dir = os.path.join(home_dir, '.credentials')
    if not os.path.exists(credential_dir):
    credential_path = os.path.join(credential_dir,
    store = Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
        flow.user_agent = APPLICATION_NAME
        credentials = tools.run_flow(flow, store, flags)
#    else: # Needed only for compatibility with Python 2.6
#        credentials = tools.run_flow(flow, store)
    print('Storing credentials to ' + credential_path)

    return credentials

SCOPES = ['']
CLIENT_SECRET_FILE = 'credentials.json'
APPLICATION_NAME = 'Tidsreg files searching script v1.14'
credentials = get_credentials()                                                
http = credentials.authorize(httplib2.Http())
drive_service_v3 ='drive', 'v3', http=http) 

Docker runs container and there is a message in console to enter pass phrase from Google to get .json with credentials. And it works. Thanks everyone for help.