Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use chromedp with docker-headless-shell #377

Closed
invasionofsmallcubes opened this issue Jun 5, 2019 · 7 comments
Closed

How to use chromedp with docker-headless-shell #377

invasionofsmallcubes opened this issue Jun 5, 2019 · 7 comments

Comments

@invasionofsmallcubes
Copy link

invasionofsmallcubes commented Jun 5, 2019

What versions are you running?

[[constraint]]
  name = "github.com/chromedp/chromedp"
  version = "0.3.0"

What did you do? Include clear steps.

Hi guys, I tried to look something using google but I couldn't find anything related to it.
If I use docker-headless-shell, how do I use chromedp to connect remotely to docker, go to a page and generate a pdf?
I mean, I understood I should use RemoteAllocatorbut it would be nice to have an example if possible.

It's basically help wanted. Thank you if you can answer me.

@mvdan
Copy link
Contributor

mvdan commented Jun 6, 2019

Hi,

You don't need to use RemoteAllocator. Usually, the simplest solution is to run your Go binary from within the docker image with headless-shell, and then let chromedp execute headless-shell.

I'll add this to the FAQ.

@mvdan mvdan closed this as completed in 5249736 Jun 10, 2019
@vianhanif
Copy link

@mvdan would you please give a small example on this in setting up a dockerized golang app with headless-shell ? Thanks

@lifegit
Copy link

lifegit commented Jun 9, 2021

@vianhanif

Excuse me, have you solved it?

@ZekeLu
Copy link
Member

ZekeLu commented Jun 10, 2021

With ExecAllocator

There are two ways to run your Go binary from within the docker image.

1. build an image based on chromedp/headless-shell

Here is an example Dockerfile:

# =============== build stage ===============
FROM golang:1.16.5-buster AS build
WORKDIR /app

COPY go.* ./
RUN go mod download -x all

COPY . ./
# ldflags:
#  -s: disable symbol table
#  -w: disable DWARF generation
# run `go tool link -help` to get the full list of ldflags
RUN go build -ldflags "-s -w" -o the-excellent-app -v path/to/main.go

# =============== final stage ===============
FROM chromedp/headless-shell:93.0.4535.3 AS final

WORKDIR /app
COPY --from=build /app/the-excellent-app ./
ENTRYPOINT ["/app/the-excellent-app", "-other", "flags"]

Build it and then run this image.

2. use volume to run your app without creating a new image (useful for temporary testing)

Build you app on the host computer first, then run this command (make sure your pre-compiled app is in the current working directory):

docker run \
    --rm \
    --volume=$PWD:/chromedp \
    --entrypoint=/chromedp/the-excellent-app \
    --env=PATH=/headless-shell \
    chromedp/headless-shell:93.0.4535.3

With RemoteAllocator

The PR #817 makes it easy to use a standalone chromedp/headless-shell container with RemoteAllocator. Check #817 (comment) for a full example.

@lifegit
Copy link

lifegit commented Jun 10, 2021

@ZekeLu
Thank!

Do you recommend option 1 or option 2 ?

1: docker images size 260mb, is huge, I'm worried.

2: It's a lot smaller, but need to install chrome on the host in advance.

@ZekeLu
Copy link
Member

ZekeLu commented Jun 10, 2021

I would choose option 1, because it will make it easy to deploy the app.

And in my opinion, 260mb is not big (and far from huge 😄 ). If you install chrome on the host, it will take up remarkable spaces too (I don't know how much it will take, but the size of chrome-linux.zip for the latest build of Chromium is 140+MB).

@lifegit
Copy link

lifegit commented Jun 10, 2021

thank!
I think a good go docker image is only a few mb (3mb-5mb), because it doesn't have a runtime。

Although each version needs 260mb, But it's very convenient ! so, take your advice , option 1 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants