Merge pull request #13209 from docker/master

Publish updates from master
This commit is contained in:
Usha Mandya 2021-07-21 16:25:41 +01:00 committed by GitHub
commit 8a1f0097f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 35 additions and 25 deletions

View File

@ -33,13 +33,23 @@ To get started with Dev Environments, you must have the following tools and exte
Click **Install** to download and install any missing tools. Click **Install** to download and install any missing tools.
### Add Git to your PATH on Windows
If you have already installed Git, and it's not detected properly, run the following command to check whether you can use Git with the CLI or PowerShell:
`$ git --version`
If it doesn't detect Git as a valid command, you must reinstall Git and ensure you choose the option **Git from the command line...** or the **Use Git and optional Unix tools...** on the **Adjusting your PATH environment** step.
![Windows add Git to path](/images/dev-env-gitbash.png){:width="300px"}
## Start a single container Dev Environment ## Start a single container Dev Environment
The simplest way to get started with Dev Environments is to create a new environment by cloning the Git repository of the project you are working on. For example, let us create a new Dev Environment using a simple `single-dev-env` project from the [Docker Samples](https://github.com/dockersamples/single-dev-env){:target="_blank" rel="noopener" class="_"} GitHub repository. The simplest way to get started with Dev Environments is to create a new environment by cloning the Git repository of the project you are working on. For example, let us create a new Dev Environment using a simple `single-dev-env` project from the [Docker Samples](https://github.com/dockersamples/single-dev-env){:target="_blank" rel="noopener" class="_"} GitHub repository.
> **Note** > **Note**
> >
> When cloning a Git repository using SSH, ensure you've added your SSH key to the ssh-agent. To do this, open a terminal and run `ssh-add <path to your public ssh key>`. > When cloning a Git repository using SSH, ensure you've added your SSH key to the ssh-agent. To do this, open a terminal and run `ssh-add <path to your private ssh key>`.
1. First, let's copy `git@github.com:dockersamples/single-dev-env.git` and add it to the **Create** field on the **Create a Development Environment** page. 1. First, let's copy `git@github.com:dockersamples/single-dev-env.git` and add it to the **Create** field on the **Create a Development Environment** page.
2. Now, click **Create**. 2. Now, click **Create**.

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -170,13 +170,13 @@ context, refer to [exclude with .dockerignore](#exclude-with-dockerignore).
> >
> docker build -t myimage:latest -<<EOF > docker build -t myimage:latest -<<EOF
> FROM busybox > FROM busybox
> COPY somefile.txt . > COPY somefile.txt ./
> RUN cat /somefile.txt > RUN cat /somefile.txt
> EOF > EOF
> >
> # observe that the build fails > # observe that the build fails
> ... > ...
> Step 2/3 : COPY somefile.txt . > Step 2/3 : COPY somefile.txt ./
> COPY failed: stat /var/lib/docker/tmp/docker-builder249218248/somefile.txt: no such file or directory > COPY failed: stat /var/lib/docker/tmp/docker-builder249218248/somefile.txt: no such file or directory
> ``` > ```
@ -206,7 +206,7 @@ touch somefile.txt
# build an image using the current directory as context, and a Dockerfile passed through stdin # build an image using the current directory as context, and a Dockerfile passed through stdin
docker build -t myimage:latest -f- . <<EOF docker build -t myimage:latest -f- . <<EOF
FROM busybox FROM busybox
COPY somefile.txt . COPY somefile.txt ./
RUN cat /somefile.txt RUN cat /somefile.txt
EOF EOF
``` ```
@ -232,7 +232,7 @@ the `hello.c` file from the ["hello-world" Git repository on GitHub](https://git
```bash ```bash
docker build -t myimage:latest -f- https://github.com/docker-library/hello-world.git <<EOF docker build -t myimage:latest -f- https://github.com/docker-library/hello-world.git <<EOF
FROM busybox FROM busybox
COPY hello.c . COPY hello.c ./
EOF EOF
``` ```

View File

@ -40,7 +40,7 @@ builder pattern above:
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
FROM golang:1.16 FROM golang:1.16
WORKDIR /go/src/github.com/alexellis/href-counter/ WORKDIR /go/src/github.com/alexellis/href-counter/
COPY app.go . COPY app.go ./
RUN go get -d -v golang.org/x/net/html \ RUN go get -d -v golang.org/x/net/html \
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . && CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
``` ```
@ -57,7 +57,7 @@ and forget to continue the line using the `\` character, for example.
FROM alpine:latest FROM alpine:latest
RUN apk --no-cache add ca-certificates RUN apk --no-cache add ca-certificates
WORKDIR /root/ WORKDIR /root/
COPY app . COPY app ./
CMD ["./app"] CMD ["./app"]
``` ```
@ -103,13 +103,13 @@ multi-stage builds.
FROM golang:1.16 FROM golang:1.16
WORKDIR /go/src/github.com/alexellis/href-counter/ WORKDIR /go/src/github.com/alexellis/href-counter/
RUN go get -d -v golang.org/x/net/html RUN go get -d -v golang.org/x/net/html
COPY app.go . COPY app.go ./
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
FROM alpine:latest FROM alpine:latest
RUN apk --no-cache add ca-certificates RUN apk --no-cache add ca-certificates
WORKDIR /root/ WORKDIR /root/
COPY --from=0 /go/src/github.com/alexellis/href-counter/app . COPY --from=0 /go/src/github.com/alexellis/href-counter/app ./
CMD ["./app"] CMD ["./app"]
``` ```
@ -143,13 +143,13 @@ Dockerfile are re-ordered later, the `COPY` doesn't break.
FROM golang:1.16 AS builder FROM golang:1.16 AS builder
WORKDIR /go/src/github.com/alexellis/href-counter/ WORKDIR /go/src/github.com/alexellis/href-counter/
RUN go get -d -v golang.org/x/net/html RUN go get -d -v golang.org/x/net/html
COPY app.go . COPY app.go ./
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
FROM alpine:latest FROM alpine:latest
RUN apk --no-cache add ca-certificates RUN apk --no-cache add ca-certificates
WORKDIR /root/ WORKDIR /root/
COPY --from=builder /go/src/github.com/alexellis/href-counter/app . COPY --from=builder /go/src/github.com/alexellis/href-counter/app ./
CMD ["./app"] CMD ["./app"]
``` ```

View File

@ -152,8 +152,8 @@ In its simplest form, the `COPY` command takes two parameters. The first paramet
Well copy the `go.mod` and `go.sum` file into our working directory `/app` which, owing to our use of `WORKDIR`, is the current directory (`.`) inside the image. Well copy the `go.mod` and `go.sum` file into our working directory `/app` which, owing to our use of `WORKDIR`, is the current directory (`.`) inside the image.
```dockerfile ```dockerfile
COPY go.mod . COPY go.mod ./
COPY go.sum . COPY go.sum ./
``` ```
Now that we have the module files inside the Docker image that we are building, we can use the `RUN` command to execute the command `go mod download` there as well. This works exactly the same as if we were running `go` locally on our machine, but this time these Go modules will be installed into the a directory inside our image. Now that we have the module files inside the Docker image that we are building, we can use the `RUN` command to execute the command `go mod download` there as well. This works exactly the same as if we were running `go` locally on our machine, but this time these Go modules will be installed into the a directory inside our image.
@ -167,7 +167,7 @@ At this point, we have an image that is based on Go environment version 1.16 (or
The next thing we need to do is to copy our source code into the image. Well use the `COPY` command just like we did with our module files before. The next thing we need to do is to copy our source code into the image. Well use the `COPY` command just like we did with our module files before.
```dockerfile ```dockerfile
COPY *.go . COPY *.go ./
``` ```
This `COPY` command uses a wildcard to copy all files with `.go` extension located in the current directory on the host (the directory where the `Dockerfile` is located) into the current directory inside the image. This `COPY` command uses a wildcard to copy all files with `.go` extension located in the current directory on the host (the directory where the `Dockerfile` is located) into the current directory inside the image.
@ -195,11 +195,11 @@ FROM golang:1.16-alpine
WORKDIR /app WORKDIR /app
COPY go.mod . COPY go.mod ./
COPY go.sum . COPY go.sum ./
RUN go mod download RUN go mod download
COPY *.go . COPY *.go ./
RUN go build -o /docker-gs-ping RUN go build -o /docker-gs-ping
@ -218,8 +218,8 @@ FROM golang:1.16-alpine
WORKDIR /app WORKDIR /app
# Download necessary Go modules # Download necessary Go modules
COPY go.mod . COPY go.mod ./
COPY go.sum . COPY go.sum ./
RUN go mod download RUN go mod download
# ... the rest of the Dockerfile is ... # ... the rest of the Dockerfile is ...
@ -351,11 +351,11 @@ FROM golang:1.16-buster AS build
WORKDIR /app WORKDIR /app
COPY go.mod . COPY go.mod ./
COPY go.sum . COPY go.sum ./
RUN go mod download RUN go mod download
COPY *.go . COPY *.go ./
RUN go build -o /docker-gs-ping RUN go build -o /docker-gs-ping

View File

@ -45,7 +45,7 @@ $ curl http://localhost:8080/
curl: (7) Failed to connect to localhost port 8080: Connection refused curl: (7) Failed to connect to localhost port 8080: Connection refused
``` ```
Our curl command failed because the connection to our server was refused. Meaning that we were not able to connect to localhost on port 8080. This is expected because our container is run in isolation which includes networking. Lets stop the container and restart with port 8080 published on our local network. Our curl command failed because the connection to our server was refused. Meaning that we were not able to connect to localhost on port 8080. This is expected because our container is running in isolation which includes networking. Lets stop the container and restart with port 8080 published on our local network.
To stop the container, press ctrl-c. This will return you to the terminal prompt. To stop the container, press ctrl-c. This will return you to the terminal prompt.

View File

@ -33,7 +33,7 @@ $ curl --request GET \
curl: (7) Failed to connect to localhost port 8080: Connection refused curl: (7) Failed to connect to localhost port 8080: Connection refused
``` ```
As you can see, our `curl` command failed because the connection to our server was refused. This means, we were not able to connect to the localhost on port 8080. This is expected because our container is run in isolation which includes networking. Lets stop the container and restart with port 8080 published on our local network. As you can see, our `curl` command failed because the connection to our server was refused. It means that we were not able to connect to the localhost on port 8080. This is expected because our container is running in isolation which includes networking. Lets stop the container and restart with port 8080 published on our local network.
To stop the container, press `ctrl-c`. This will return you to the terminal prompt. To stop the container, press `ctrl-c`. This will return you to the terminal prompt.

View File

@ -38,7 +38,7 @@ $ curl --request POST \
curl: (7) Failed to connect to localhost port 8000: Connection refused curl: (7) Failed to connect to localhost port 8000: Connection refused
``` ```
Our curl command failed because the connection to our server was refused. Meaning that we were not able to connect to localhost on port 8000. This is expected because our container is run in isolation which includes networking. Lets stop the container and restart with port 8000 published on our local network. Our curl command failed because the connection to our server was refused. It means that we were not able to connect to localhost on port 8000. This is expected because our container is running in isolation which includes networking. Lets stop the container and restart with port 8000 published on our local network.
To stop the container, press ctrl-c. This will return you to the terminal prompt. To stop the container, press ctrl-c. This will return you to the terminal prompt.