├── .dockerignore ├── .gitignore ├── CmdLine.cpp ├── CmdLine.hpp ├── Dockerfile ├── LICENSE.md ├── Makefile ├── README.md └── main.cpp /.dockerignore: -------------------------------------------------------------------------------- 1 | *.cpp 2 | *.hpp 3 | *.o 4 | LICENSE.md 5 | README.md 6 | .git 7 | .gitignore 8 | BoostTest 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *~ 3 | .*~ 4 | *.o 5 | test 6 | BoostTest 7 | -------------------------------------------------------------------------------- /CmdLine.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include "CmdLine.hpp" 9 | 10 | namespace po = boost::program_options; 11 | 12 | CmdLine::CmdLine(int argCount, char **argVar){ 13 | 14 | try{ 15 | po::options_description desc("Allowed options"); 16 | desc.add_options() 17 | ("help,h", "Prints help message.") 18 | ("val,v", po::value(&val)->required(), "Test value to be printed."); 19 | 20 | po::variables_map vm; 21 | 22 | try{ 23 | 24 | po::store(po::parse_command_line(argCount, argVar, desc), vm); 25 | 26 | 27 | if(vm.count("help")){ 28 | std::cout << "\n\n" << desc << "\n\n" << std::endl; 29 | exit(0); 30 | } 31 | 32 | po::notify(vm); 33 | 34 | } 35 | 36 | // catch any errors in boost argument parsing. 37 | catch(po::error& e){ 38 | std::cout << "\nerror: " << e.what() << std::endl; 39 | std::cout << "\n\n" << "Usage: ./test -v " << std::endl; 40 | std::cout << "\nFor additional options type: ./test -h\n" << std::endl; 41 | exit(EXIT_FAILURE); 42 | } 43 | 44 | } 45 | 46 | // catch any other exceptions/errors in standard argument parsing. 47 | catch(std::exception& e){ 48 | std::cout << std::endl << e.what() << std::endl; 49 | exit(EXIT_FAILURE); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /CmdLine.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CmdLine_HPP 2 | #define CmdLine_HPP 3 | 4 | class CmdLine { 5 | 6 | public: 7 | CmdLine(int argCount, char **argVar); 8 | double val; 9 | 10 | }; 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # This is a test Dockerfile. 2 | 3 | FROM ubuntu 4 | 5 | MAINTAINER Paul Blischak 6 | 7 | # Get g++ for compiling, wget to download Boost, git to clone source code repo, 8 | # and make to automate program compilation with Makefile provided 9 | RUN apt-get update \ 10 | && apt-get install -y git \ 11 | g++ \ 12 | make \ 13 | wget 14 | 15 | # Download boost, untar, setup install with bootstrap and only do the Program Options library, 16 | # and then install 17 | RUN cd /home && wget http://downloads.sourceforge.net/project/boost/boost/1.60.0/boost_1_60_0.tar.gz \ 18 | && tar xfz boost_1_60_0.tar.gz \ 19 | && rm boost_1_60_0.tar.gz \ 20 | && cd boost_1_60_0 \ 21 | && ./bootstrap.sh --prefix=/usr/local --with-libraries=program_options \ 22 | && ./b2 install \ 23 | && cd /home \ 24 | && rm -rf boost_1_60_0 25 | 26 | # Clone git repository with dummy C++ program, use make to compile, install it, then remove the repo 27 | RUN cd /home \ 28 | && git clone https://github.com/pblischak/boost-docker-test.git \ 29 | && cd /home/boost-docker-test \ 30 | && make linux \ 31 | && make install \ 32 | && cd .. \ 33 | && rm -rf boost-docker-test 34 | 35 | CMD ["bash"] 36 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Paul Blischak 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | BOOST_LIB = /usr/local/lib 2 | BOOST_INC = /usr/local/include 3 | 4 | EXE = BoostTest 5 | OBJ = CmdLine.o main.o 6 | 7 | CXX=g++ 8 | CXXFLAGS = -I${BOOST_INC} -O3 -g -std=c++11 -fopenmp 9 | LDFLAGS = -lboost_program_options 10 | 11 | .PHONY : install uninstall clean 12 | 13 | all : 14 | @echo "Please enter either 'make mac' on a Mac, or 'make linux' on a Linux computer." 15 | 16 | linux : $(OBJ) 17 | $(CXX) $(CXXFLAGS) -L${BOOST_LIB} -Wl,-rpath=/usr/local/lib -o $(EXE) $^ $(LDFLAGS) 18 | 19 | mac : $(OBJ) 20 | $(CXX) $(CXXFLAGS) -L${BOOST_LIB} -o $(EXE) $^ $(LDFLAGS) 21 | 22 | $(OBJ) : %.o: %.cpp 23 | $(CXX) $(CXXFLAGS) -o $@ -c $< 24 | 25 | install : 26 | @cp $(EXE) /usr/local/bin 27 | 28 | uninstall : 29 | @rm -i /usr/local/bin/$(EXE) 30 | 31 | clean : 32 | @rm -i *.o $(EXE) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Creates a Docker image with a C++ program that links to the Boost C++ libraries 2 | 3 | The resulting image is on Docker Hub: pblischak/boost-test. 4 | 5 | Pull it within a Docker Quickstart Terminal 6 | 7 | ``` 8 | docker pull pblischak/boost-test 9 | ``` 10 | 11 | Then run it using `docker run`: 12 | 13 | ``` 14 | docker run -it pblischak/boost-test 15 | ``` 16 | 17 | This puts you in a bash environment where the `BoostTest` executable is available. Try running: 18 | 19 | ``` 20 | BoostTest -h 21 | BoostTest -v 1234 22 | ``` 23 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include "CmdLine.hpp" 8 | 9 | int main(int argc, char **argv){ 10 | 11 | CmdLine cmd(argc, argv); 12 | 13 | std::cout << "\n\n**** Start ****\n\n"; 14 | 15 | std::cout << std::setw(10) << std::setprecision(10) << "\nCommand line value: " << cmd.val << "\n"; 16 | 17 | std::cout << "\nParallelization with OpenMP test...\n\n"; 18 | 19 | std::cout << "Loop 1 through 10 in parallel and print to STDOUT (not necessarily in order)...\n\n"; 20 | 21 | #pragma omp parallel for 22 | for(int i = 0; i < 10; i++){ 23 | 24 | #pragma omp critical 25 | std::cout << i + 1 << "\n"; 26 | 27 | } 28 | 29 | std::cout << "\n\n**** Done ****\n\n"; 30 | 31 | return 0; 32 | 33 | } 34 | --------------------------------------------------------------------------------