Docker Community Forums

Share and learn in the Docker community.

Out of box fail - Powershell

In the getting started section it asks you to build a simple dockerfile.

This happens - anyone have any idea why?

Win 10 Surface Book 2 - Powershell Admin

Here’s the instructions from the web page

Step 4: Build and push a container image to Docker Hub from your computer

Start by creating a Dockerfile to specify your application as shown below. (More on Dockerfiles here)

cat > Dockerfile <<EOF
FROM busybox
CMD echo "Hello world! This is my first Docker image."
EOF

Here is what happens


Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\WINDOWS\system32> cat > Dockerfile <<EOF
At line:1 char:19
+ cat > Dockerfile <<EOF
+                   ~
Missing file specification after redirection operator.
At line:1 char:18
+ cat > Dockerfile <<EOF
+                  ~
The '<' operator is reserved for future use.
At line:1 char:19
+ cat > Dockerfile <<EOF
+                   ~
The '<' operator is reserved for future use.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingFileSpecification

PS C:\WINDOWS\system32>

After the powershell fail I tried cmder - same fail
Then I tried Mingw64 and it worked as directed.

The next step BOLDED failed in all three

Instruction

Step 4: Build and push a container image to Docker Hub from your computer

Start by creating a Dockerfile to specify your application as shown below. (More on Dockerfiles here)

cat > Dockerfile <<EOF
FROM busybox
CMD echo "Hello world! This is my first Docker image."
EOF

1. Run docker build -t <your_username>/my-first-repo . to build your Docker image
2. Test your docker image locally by running docker run <your_username>/my-first-repo

Produced this result

denniswillis@DennisSB2 MINGW64 ~
$ docker build -t denniswillis/my-first-repo
“docker build” requires exactly 1 argument.
See ‘docker build --help’.

Usage: docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile

denniswillis@DennisSB2 MINGW64 ~

Hours lost just getting started.

PowerShell doesn’t understand bash commands (or not all of them). If you want to write directly into a file from PowerShell console you can use

@'
FROM busybox
CMD echo "Hello world! This is my first Docker image."
'@ | Out-File Dockerfile

Thanks. It’s hard to follow the get started instructions. Any ideas regarding the flag -t?

Yes of course, this flag is documented in the docs for docker run.
But maybe you are taking the wrong approach. Instead of reading ‘getting started’ tutorials it could be better to follow a course with detailed instructions, for example Docker Mastery on Udemy.

I thought I’d leave a record here if anyone else experienced these “gotcha’s” on the “Getting Started” docs.