what is the comand to build a docker image
Answers
Answer:
Build and test your image
Answer:
Build and test your image
Now that you have some source code and a Dockerfile, it’s time to build your first image, and make sure the containers launched from it work as expected.
Make sure you’re in the directory node-bulletin-board/bulletin-board-app in a terminal or PowerShell using the cd command. Run the following command to build your bulletin board image:
docker build --tag bulletinboard:1.0 .
You’ll see Docker step through each instruction in your Dockerfile, building up your image as it goes. If successful, the build process should end with a message Successfully tagged bulletinboard:1.0.
Windows users:
This example uses Linux containers. Make sure your environment is running Linux containers by right-clicking on the Docker logo in your system tray, and clicking Switch to Linux containers. Don’t worry - all the commands in this tutorial work the exact same way for Windows containers.
You may receive a message titled ‘SECURITY WARNING’ after running the image, noting the read, write, and execute permissions being set for files added to your image. We aren’t handling any sensitive information in this example, so feel free to disregard the warning in this example.
Run your image as a container
Run the following command to start a container based on your new image:
docker run --publish 8000:8080 --detach --name bb bulletinboard:1.0
There are a couple of common flags here:
--publish asks Docker to forward traffic incoming on the host’s port 8000 to the container’s port 8080. Containers have their own private set of ports, so if you want to reach one from the network, you have to forward traffic to it in this way. Otherwise, firewall rules will prevent all network traffic from reaching your container, as a default security posture.
--detach asks Docker to run this container in the background.
--name specifies a name with which you can refer to your container in subsequent commands, in this case bb.
Visit your application in a browser at localhost:8000. You should see your bulletin board application up and running. At this step, you would normally do everything you could to ensure your container works the way you expected; now would be the time to run unit tests, for example.
Once you’re satisfied that your bulletin board container works correctly, you can delete it:
docker rm --force bb
The --force option stops a running container, so it can be removed. If you stop the container running with docker stop bb first, then you do not need to use --force to remove it.
Conclusion
At this point, you’ve successfully built an image, performed a simple containerization of an application, and confirmed that your app runs successfully in its container. The next step will be to share your images on Docker Hub, so they can be easily downloaded and run on any destination